gulp压缩代码的问题?

发布于 2022-09-07 04:24:27 字数 4201 浏览 25 评论 0

14:13:13] Starting 'agency:build'...

events.js:183
      throw er; // Unhandled 'error' event
      ^
Error
    at new JS_Parse_Error (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:1534:18)
    at js_error (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:1542:11)
    at croak (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2089:9)
    at token_error (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2097:9)
    at expect_token (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2110:9)
    at expect (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2113:36)
    at regular_for (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2354:9)
    at for_ (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2350:16)
    at eval (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2229:24)
    at eval (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2136:24)
    

其中agencySource...后面的是路径,压缩代码的时候报错,不知道该怎么压缩代码了?

    gulp.task('agency:cache-templates', function() {
                    var options = {
                        removeComments: true, //清除HTML注释
                        collapseWhitespace: true, //压缩HTML
                        collapseBooleanAttributes: false, //省略布尔属性的值 <input checked="true"/> ==> <input />
                        removeEmptyAttributes: true, //删除所有空格作属性值 <input id="" /> ==> <input />
                        removeScriptTypeAttributes: true, //删除<script>的type="text/javascript"
                        removeStyleLinkTypeAttributes: true, //删除<style>和<link>的type="text/css"
                        minifyJS: true, //压缩页面JS
                        minifyCSS: true //压缩页面CSS
                    };
                    return gulp.src([agencySource.js.staticViews, agencySource.js.views])
                        .pipe(htmlmin(options))
                        .pipe(templateCache('app.js', {
                            root: 'views',
                            module: 'app'
                        }))
                        .pipe(gulp.dest(agencySource.build.cache));
                });
                
                gulp.task('agency:build', ['agency:cache-templates'], function() {
                    
                    agencySource.js.src.push(agencySource.build.cache + '/app.js');
                    return gulp.src(agencySource.js.src)
                        .pipe(ngAnnotate())
                        //.pipe(uglify())
                        .pipe(concat('app.js'))
                        .pipe(gulp.dest(agencySource.build.cache));
                });
   
   
   
   我在 `https://www.npmjs.com/package/gulp-uglify`中找到了,但是不知道怎么用?
   var uglifyjs = require('uglify-js'); // can be a git checkout 
                                             // or another module (such as `uglify-es` for ES6 support) 
        var composer = require('gulp-uglify/composer');
        var pump = require('pump');
         
        var minify = composer(uglifyjs, console);
         
        gulp.task('compress', function (cb) {
          // the same options as described above 
          var options = {};
         
          pump([
              gulp.src('lib/*.js'),
              minify(options),
              gulp.dest('dist')
            ],
            cb
          );
        });

大佬们帮我看看、、、、谢谢!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹雨成花 2022-09-14 04:24:27

https://www.npmjs.com/package...

gulp.task('agency:build', ['agency:cache-templates'], function(cb) {
    agencySource.js.src.push(agencySource.build.cache + '/app.js');
    pump([
        gulp.src(agencySource.js.src)
            .pipe(ngAnnotate()).pipe(babel()).pipe(concat('app.js')),
            uglify(),
            gulp.dest(agencySource.build.cache)
            // .pipe(concat('app.js'))
            // .pipe(gulp.dest(agencySource.build.cache))
    ],cb);
        
});
滥情空心 2022-09-14 04:24:27

不压缩,运行gulp有问题吗?应该是你之前写的代码里面格式有问题,但是gulp不会提醒是哪里报错了,安装elist检查一下,兄弟你这工作量会有点大

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文