Uglify SyntaxError:意外的标记:punc()) [英] Uglify SyntaxError: Unexpected token: punc ())

查看:561
本文介绍了Uglify SyntaxError:意外的标记:punc())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gulp来缩小包含JS文件的文件夹。然而,其中一个文件有上述错误,以防止它被缩小。



我设法捕获并打印出我在这里部分打印的错误:

  JS_Parse_Error {
message:'SyntaxError:Unexpected token:punc())',
filename:' ex.js',
行:189,
col:25,
pos:6482,
堆栈:Error在New JS_Parse_Error(在<匿名>评估时)。 ..)
插件:'gulp-uglify',
fileName:'... / js / ex.js',
showStack:false
}

有问题的文件包含以下内容,简称:

<$ p $ (
按钮:{
confirm:function(){
$(
$ .confirm()){
$> .post('/ ajax-handler',{
...
})
.done(function(response){
var data = filterResponse(response);
if( data ['status'] =='success'){
sleep(1000).then(()=> {
* ...
});
sleep(5000).then(()=> {
...
});

} else {
console.log('Oops!');

})
.fail(函数(err,status,response){
...
});
},
cancel:function(){}
}
});
...
}

我按顺序加上了*以指示JS_Parse_Error列出的确切位置。

解决方案

我希望你能从webpack的这个解决方案中获得灵感。 (下面的链接)

简单教UglifyJS ES6



有两个版本UglifyJS - ES5 ES6 (和谐),请参阅git

ES5版本默认安装了所有插件,但是如果您明确安装Harmony版本,那么这些插件将使用它。



package.json

 uglify -js:git + https://github.com/mishoo /UglifyJS2.git#harmony

  npm install --save uglify -js @ github:mishoo / UglifyJS2#harmony 

yarn add git://github.com/mishoo/UglifyJS2#harmony --dev






Webpack



要在webpack中使用它,还需要安装webpack插件

  npm install uglifyjs-webpack-plugin --save-dev 

yarn add uglifyjs-webpack-plugin --dev

然后导入手动安装的插件

  var UglifyJSPlugin = require('uglifyjs-webpack-plugin'); 

并将其替换为代码

<$ p $新的webpack.optimize.UglifyJsPlugin({...})
+ new UglifyJSPlugin({...})






有关更多webpack信息(安装/用法),请参阅 https://github.com/webpack-contrib/uglifyjs-webpack-plugin#install


I am trying to use gulp in order to minify a folder containing JS files. However, one of the files has the above error, preventing it from being minified.

I managed to catch and print the error, which I've partially printed here:

JS_Parse_Error {
 message: 'SyntaxError: Unexpected token: punc ())',
 filename: 'ex.js',
 line: 189,
 col: 25,
 pos: 6482,
 stack: Error\n    at new JS_Parse_Error (eval at <anonymous> ... ) 
 plugin: 'gulp-uglify',
 fileName: '.../js/ex.js',
 showStack: false
}

The file in question contains the following, shortened:

function() {
  ...
  $.confirm({
    buttons: {
        confirm: function() {
            $.post('/ajax-handler', {
                    ...
                })
                .done( function(response) {
                    var data = filterResponse(response);
                    if (data['status'] == 'success') {
                        sleep(1000).then(() => {
                    *       ...
                        });
                        sleep(5000).then(() => {
                            ...  
                        });

                    } else {
                        console.log('Oops!');
                    }
                })
                .fail( function(err, status, response) {
                    ...
            });
        },
        cancel: function() {}
    }
 });
  ...
}

I added the "*" above in order to indicate the exact position listed by JS_Parse_Error.

解决方案

I hope you can get inspired by this solution which works with webpack. (link below)

Simply teach UglifyJS ES6

There are two versions of UglifyJS - ES5 and ES6 (Harmony), see on git
ES5 version comes by default with all the plugins, but if you install a Harmony version explicitly, those plugins will use it instead.

package.json

"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"

or

npm install --save uglify-js@github:mishoo/UglifyJS2#harmony

yarn add git://github.com/mishoo/UglifyJS2#harmony --dev


Webpack

To use it with webpack install also the webpack plugin

npm install uglifyjs-webpack-plugin --save-dev

yarn add uglifyjs-webpack-plugin --dev

then import the manually installed plugin

var UglifyJSPlugin = require('uglifyjs-webpack-plugin');

and replace it in code

-  new webpack.optimize.UglifyJsPlugin({ ... })
+  new UglifyJSPlugin({ ... })


For more webpack info (Installation/Usage) see https://github.com/webpack-contrib/uglifyjs-webpack-plugin#install

这篇关于Uglify SyntaxError:意外的标记:punc())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆