Gulp - 使用 gulp-uglify 和 gulp-concat 的意外令牌错误

Gulp - unexpected token error using gulp-uglify and gulp-concat

本文关键字:意外 令牌 错误 gulp-concat 使用 gulp-uglify Gulp      更新时间:2023-09-26

这是我的代码

gulp.task('js', function () {
return gulp.src(['public/js/angular.js','public/js/app.js', 'public/js/**/*.js'])
    .pipe(plumber({
        errorHandler: function(err){
            console.log(err);
            this.emit('end');
        }
    }))
    .pipe(concat('filename.min.js'))
    .pipe(uglify().on('error', gutil.log))
    .pipe(gulp.dest('public/js') //destination of new file
    .pipe(notify({ message: 'Finished minifying JavaScript'})))
gulp.task('watch', function(){
    gulp.watch('app/assets/sass/**/*', ['css']);
    gulp.watch('public/js/**/*', ['js']);
});

对任何 js 文件进行更改后出现控制台错误:

/

projects/miche-web/public/js/miche.min.js:意外的令牌名称"替换",预期的双关语",»] 消息: '/Users/projects/miche-web/public/js/miche.min.js: 意外的令牌名称 «替换», 预期的双关语 «,», 文件名: '/Users/projects/miche-web/public/js/miche.min.js', 行号: 247,

但是,该文件是空白的,因此我无法引用第 247 行的错误。

有什么想法吗?

您的pipe调用中存在语法错误。观察以下内容...

.pipe(gulp.dest('public/js') //destination of new file

=>

.pipe(gulp.dest('public/js')) //destination of new file

请注意初始函数调用中缺少)