简体   繁体   English

吞咽uglify不起作用

[英]gulp-uglify not working

Here is my repository https://github.com/shellwe/QA_WP_Template 这是我的存储库https://github.com/shellwe/QA_WP_Template

If you just needed to see the code snippet; 如果您只需要查看代码片段,请参阅; here it is 这里是

gulp.task('uglify', function() {
      return gulp.src('js/all.min.js')
        .pipe(uglify())
        .pipe(gulp.dest('js/'));
});

I am running "gulp uglify" and I am getting the following errors. 我正在运行“ gulp uglify”,并且收到以下错误。

events.js:160
      throw er; // Unhandled 'error' event
      ^
 Error
    at new JS_Parse_Error (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:1534:18)
    at js_error (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:1542:11)
    at croak (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2089:9)
    at token_error (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2097:9)
    at unexpected (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2103:9)
    at semicolon (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2123:56)
    at simple_statement (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2314:73)
    at eval (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2183:19)
    at eval (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2136:24)
    at eval (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2904:23)

Most examples I see had concat and uglify in one process but since the concat part was working I broke them apart to show that. 我看到的大多数示例在一个过程中都进行了合并和丑化,但是由于合并部分一直在工作,所以我将它们分解以表明这一点。 I know its something wrong with uglify, I just can't figure out what I am doing wrong. 我知道uglify出了点问题,我只是弄不清楚我在做什么错。

The error you are getting doesn't really explain much... However, according to the little "documentation" on npm.js of gulp-uglify , 您遇到的错误并不能真正解释很多...但是,根据gulp - uglify的npm.js上的小“文档”,

To help properly handle error conditions with Node stream, this project recommends the use of pump 为了帮助正确处理Node流的错误情况,该项目建议使用Pump

You can read up on gulp-uglify and pump . 您可以阅读gulp-uglifypump

So, I tried the following: 因此,我尝试了以下方法:

# grab pump
npm install pump --save-dev

Then, in the gulpfile.js , I did the following: 然后,在gulpfile.js中 ,我执行了以下操作:

gulp.task('uglify2', function (cb) {
    pump([
        gulp.src('./js/all.min.js'),
        uglify(),
        gulp.dest('./js/')
    ],
    cb
    );
});

The error that I am getting, which by the way, is a lot nicer than the error you are getting, is the following: 我得到的错误(顺便说一句)比您得到的错误好得多,如下所示:

在此处输入图片说明

The problem seems to be on line 191 , which suggests that there is something wrong with your code , rather than your gulp task . 问题似乎在第191行,这表明您的代码有问题 ,而不是gulp任务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM