I am trying to exclude unused momentjs locales using webpack. I have tried both 3 ways below:
1- moment-locales-webpack-plugin
new MomentLocalesPlugin({
localesToKeep: ["en"]
})
2- ContextReplacementPlugin
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/)
3- ignorePlugin
new webpack.IgnorePlugin(
/^\.\/locale$/,
/moment$/
});
But, none of these methods work for me and all locales still exist in final bundle. My webpack version is 4.28.2. And I am using moment-js v 2.23.
I am trying to exclude unused momentjs locales using webpack. I have tried both 3 ways below:
1- moment-locales-webpack-plugin
new MomentLocalesPlugin({
localesToKeep: ["en"]
})
2- ContextReplacementPlugin
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/)
3- ignorePlugin
new webpack.IgnorePlugin(
/^\.\/locale$/,
/moment$/
});
But, none of these methods work for me and all locales still exist in final bundle. My webpack version is 4.28.2. And I am using moment-js v 2.23.
Share Improve this question asked Feb 20, 2019 at 14:38 Hadi RanjbarHadi Ranjbar 1,8124 gold badges24 silver badges44 bronze badges 2- Check this: github./moment/moment/issues/2517#issuement-393704231 – Prerak Sola Commented Feb 20, 2019 at 14:44
- @SergeK. That's my first solution. – Hadi Ranjbar Commented Feb 20, 2019 at 14:53
1 Answer
Reset to default 5new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/)
There is no 'en' locale in moment.js; that's why it loads all of them. Try /en-gb/
if you need only English.