gpt4 book ai didi

Gulp - gulp-uglify 事件错误

转载 作者:行者123 更新时间:2023-12-02 17:18:56 29 4
gpt4 key购买 nike

我在 HTML/JS/CSS 网站上工作,我使用 Gulp 作为自动化工具。

在运行 gulp serve 时它工作得很好,但在运行 gulp build 时我收到以下错误:

[18:24:52] Using gulpfile myProject/gulpfile.js
[18:24:52] Starting 'jshint'...
[18:24:52] Starting 'css'...
[18:24:52] Starting 'scripts'...
[18:24:52] Starting 'partials'...
[18:24:52] Starting 'images'...
[18:24:53] Starting 'videos'...
[18:24:53] Starting 'fonts'...
[18:24:53] Starting 'fileinclude'...
[18:24:53] Starting 'extras'...
[18:24:53] Finished 'jshint' after 518 ms
[18:24:53] all files 48.19 kB
[18:24:53] Finished 'fileinclude' after 245 ms

events.js:154
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)
at croak (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2089:9)
at token_error (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2097:9)
at unexpected (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2103:9)
at expr_atom (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2618:13)
at maybe_unary (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2792:19)
at expr_ops (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2827:24)
at maybe_conditional (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2832:20)
at maybe_assign (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2856:20)
at expression (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2875:20)
at expr_atom (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2608:26)
at maybe_unary (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2792:19)
at expr_ops (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2827:24)
at maybe_conditional (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2832:20)
at maybe_assign (eval at <anonymous> (myProject/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2856:20)

这是 gulpfile.js 的摘录:

/*global -$ */
'use strict';

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var sass = require('gulp-ruby-sass');
//var concat = require('gulp-concat');
var rename = require('gulp-rename');
var gulpUtil = require('gulp-util');
var uglify = require('gulp-uglify');

//script paths
var jsFiles = 'app/scripts/**/*.js',
jsDest = 'dist/scripts';

gulp.task('scripts', function() {
return gulp.src(jsFiles)
//.pipe(concat('main.js'))
.pipe(rename('main.min.js'))
.pipe(uglify()) // issue comes from here
.pipe(gulp.dest(jsDest));
});

gulp.task('build', ['jshint','css', 'scripts', 'partials', 'images', 'videos', 'fonts', 'fileinclude', 'extras'], function () {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});

gulp.task('default', ['clean'], function () {
gulp.start('build');
});

由于错误消息似乎与 uglify-js 有关,所以我尝试注释掉 scripts 中的 uglify() 调用任务,它编译得很好。

您知道为什么会这样吗?

最佳答案

找了2天发现我是let关键字,我把它换成了var并且现在一切正常。uglify 不知道如何处理 let 关键字。多么糟糕!!!

关于Gulp - gulp-uglify 事件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44594930/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com