使用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>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM