用 webpack.contextReplacementPlugin 来替换语言包的引入。
示例代码
const webpack = require('webpack');
module.exports = {
//...
plugins: [
// load `moment/locale/ja.js` and `moment/locale/it.js`
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en-gb|zh-cn/),
],
};
上面的配置可以保证 webpack 只打包因为和中文两个语言包。