鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ nuxt在build階段提示swiper錯(cuò)誤, 提示和UglifyJs有關(guān).

nuxt在build階段提示swiper錯(cuò)誤, 提示和UglifyJs有關(guān).

nuxt: 1.0.0 rc11
swiper: 4.0.5

clipboard.png

請(qǐng)問該如何解決呢?

回答
編輯回答
執(zhí)念

es6不能直接被uglify壓縮,node_module里面的第三方包都會(huì)被默認(rèn)忽略轉(zhuǎn)譯為es5。這里把你報(bào)Uglify錯(cuò)的所有包exclude進(jìn)去config.module即可。
例如你現(xiàn)在是swiper。
在nuxt.config.js里面的build的extend里增加

             config.module.rules.push({
                 test: /\.js$/,
                 loader: 'babel-loader',
                 exclude: function(modulePath) {
                     return /node_modules/.test(modulePath) &&
                         !/node_modules\/swiper/.test(modulePath);
                 },
                 options: Object.assign({}, this.babelOptions)
             })

但是我在本機(jī)上述代碼無效(window),但是在mac下有效。后來我用下面的替換就可以了。

            config.module.rules.splice(0, 0, {
                test: /\.js$/,
                include: [path.resolve(__dirname, './node_modules/swiper')],
                loader: 'babel-loader',
            })
2018年3月25日 23:49
編輯回答
艷骨

壓縮過的代碼如果再壓縮容易報(bào)錯(cuò),你看看是不是這個(gè)原因.

2017年8月2日 21:37
編輯回答
礙你眼

請(qǐng)問怎么解決???

2017年1月18日 13:03