解决:moment.js 体积过大的问题,推荐用 date-fns 代替

问题:

使用 Webpack 打包 moment.js 时,会将 moment.js 所有的 locale 全部打包进去。

解决方法 1:

Webpack plugins 选项配上:

new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(zh-cn|en-gb)$/)

解决方法 2:

推荐使用 date-fns

参考:

https://segmentfault.com/q/1010000010575043

https://github.com/date-fns/date-fns

来源:http://www.qianduan.org/post-476.html