diff --git a/index-with-locales.js b/index-with-locales.js new file mode 100644 index 0000000000..3ea9a69054 --- /dev/null +++ b/index-with-locales.js @@ -0,0 +1,11 @@ +const antd = require('./components'); +const req = require.context('./components', true, /^\.\/locale-provider\/.+_.+\.tsx$/); + +antd.locales = {}; + +req.keys().forEach((mod) => { + const match = mod.match(/\/([^/]+).tsx$/); + antd.locales[match[1]] = req(mod); +}); + +module.exports = antd; diff --git a/webpack.config.js b/webpack.config.js index 7079938c9d..c5fcd0f32e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -18,12 +18,22 @@ function es3ify(webpackConfig) { }); } +function addLocales(webpackConfig) { + let packageName = 'antd-with-locales'; + if (webpackConfig.entry['antd.min']) { + packageName += '.min'; + } + webpackConfig.entry[packageName] = './index-with-locales.js'; + webpackConfig.output.filename = '[name].js'; +} + module.exports = function (webpackConfig) { webpackConfig = getWebpackConfig(webpackConfig); if (process.env.RUN_ENV === 'PRODUCTION') { webpackConfig.forEach((config) => { es3ify(config); ignoreMomentLocale(config); + addLocales(config); }); } return webpackConfig;