注意開發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>