本文介绍了UglifyJS webpack插件抛出:意外的令牌:名称(功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经遇到过UglifyJS for Webpack和ES6模块的问题:

I used to have problems with UglifyJS for Webpack and ES6 modules:

我读到Webpack插件的新测试版支持ES6:

I read that the new beta version of the Webpack plugin supports ES6:

,我在与Uglify一起出现错误后切换到了这里。

Uglify cannot parse ES6 on its own( as far as I know), so you need to transpile your code down to ES5, post-processing your generated JS with babel, or use a different minifier. My recommendation is Babelify to which I switched after having constant errors with Uglify.

编辑:问题可能出在你的 new webpack.optimize.UglifyJsPlugin 声明中,使用Webpack 3+的声明有问题。您需要导入 uglifyjs-webpack-plugin 并将插件声明更改为 new UglifyJSPlugin (示例)。这是。

The problem might be in your new webpack.optimize.UglifyJsPlugin declaration, There are problems with using this declaration with Webpack 3+. You need to import the uglifyjs-webpack-plugin and change plugin declaration to new UglifyJSPlugin(example). Here is a reference.

示例:

const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

    const config = {
      ...
      plugins: [
        new UglifyJSPlugin({ uglifyOptions: { ...options } })
      ]
    }

这篇关于UglifyJS webpack插件抛出:意外的令牌:名称(功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 10:07