使用webpack + momentjs时, 需要注意的问题
注意开发HTML页面charset, 如是不是utf-8, 比如是shift_jis,
一般会在webpack里用插件EncodingPlugin把开发的utf-8格式转码成shift_jis格式
那么, 页面会报错如下:
中文: SCRIPT1046: strict 模式下不允许一个属性有多个定义
英文: SCRIPT1046: Multiple definitions of a property not allowed in strict mode
解决办法两种:
1. 安装MomentLocalesPlugin
npm install --save-dev moment-locales-webpack-plugin
webpack.config.js文件添加如下:
// webpack.config.js
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
module.exports = {
plugins: [
// To strip all locales except “en”
new MomentLocalesPlugin(),
// Or: To strip all locales except “en”, “es-us” and “ru”
// (“en” is built into Moment and can’t be removed)
new MomentLocalesPlugin({
localesToKeep: ['es-us', 'ru'],
}),
],
};
2.或者所有js代码一直接用uft-8格式, 在HTML引入的代码时, 这样写
<script src="../js/xxxxxxxx.bundle.min.js" charset="utf-8"></script>

浙公网安备 33010602011771号