最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Exclude unused locales momentjs using webpack - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5
new 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.

发布评论

评论列表(0)

  1. 暂无评论