From cf77ca17929ad64cd920d2adf1611a29b5ad8a0d Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 24 Aug 2023 22:44:42 +0800 Subject: [PATCH] fix(plugin-client): extract locale files of antd --- packages/plugins/client/build.js | 22 ++++++++++++++++++---- packages/plugins/client/src/server/antd.ts | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/plugins/client/build.js b/packages/plugins/client/build.js index 8516ed076..5b9cbf4e3 100644 --- a/packages/plugins/client/build.js +++ b/packages/plugins/client/build.js @@ -20,8 +20,22 @@ exports.run = async (log) => { }); log('coping antd locale'); - await fs.cp(path.resolve(path.dirname(antd)), path.resolve(localeDir, 'antd'), { - recursive: true, - force: true, - }); + const files = await fs.readdir(path.resolve(path.dirname(antd), 'locale')); + await fs.mkdir(path.resolve(localeDir, 'antd'), { force: true, recursive: true }); + for (const file of files) { + if (path.extname(file) !== '.js') { + continue; + } + const content = require(path.resolve(path.dirname(antd), 'locale', file)).default; + try { + await fs.writeFile( + path.resolve(localeDir, 'antd', file), + `module.exports = ${JSON.stringify(content)}`, + 'utf-8', + {}, + ); + } catch (error) { + log(`skip ${file}`); + } + } }; diff --git a/packages/plugins/client/src/server/antd.ts b/packages/plugins/client/src/server/antd.ts index 1b3e4b15d..190c249d5 100644 --- a/packages/plugins/client/src/server/antd.ts +++ b/packages/plugins/client/src/server/antd.ts @@ -3,7 +3,7 @@ import { resolve } from 'path'; export const getAntdLocale = (lang) => { const lng = lang.replace('-', '_'); - const files = [resolve(__dirname, `./../locale/antd/locale/${lng}`)]; + const files = [resolve(__dirname, `../locale/antd/${lng}`)]; if (process.env.APP_ENV !== 'production') { files.unshift(`antd/lib/locale/${lng}`); files.push(`antd/lib/locale/en_US`);