GulpUglifyError:无法缩小JavaScript引起:SyntaxError:意外的令牌名称«k»,预期的punc«;»

问题描述 投票:0回答:1

我收到一些奇怪的错误,但为了抑制这些错误,我必须改变我收到错误的所有内容?

//gulp file code
var fs = require('fs');
var path = require('path');`enter code here`
var merge = require('merge-stream');
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require('gulp-util');



gulp.task('css',function()
{

return gulp.src(['assets/css/*.css'])
    .pipe(sourcemaps.init())

    .pipe(sourcemaps.write())
    .pipe(uglify())
    .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
    .pipe(concat('all.css'))
    .pipe(gulp.dest('build/css'))

})
gulp.task('js',function()
{

return gulp.src(['shared/*.js','controller/*.js','directives/*.js','services/*.js'])
    .pipe(sourcemaps.init())

    .pipe(sourcemaps.write())
    .pipe(uglify())
    .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
    .pipe(concat('all.js'))
    .pipe(gulp.dest('build/js'))

})

gulp.task('default', ['css','js']);

我试图在网上找到解决方案,但没有运气

for (let k = 0; k < $scope.allCollctedTags.length; k++) 
{
 $scope.customtags.push($scope.allCollctedTags[k].text);
}

但是,如果我用var替换let,则此错误现在被删除,下一个错误来自以下代码:

$scope.multipleImages.push(...response.data.result.imageName);
but if i write it as below then this error disappear
$scope.multipleImages.push(response.data.result.imageName);

also if i use underscore js then also it give me error 
let temparray = _.difference($scope.multipleImages,$scope.extractedImagesBrowse);

现在做什么,我可以在一个或两个文件中做这些事情但是对于整个项目我不能这样做。

angularjs gulp
1个回答
5
投票

this回答之后,我发现我试图编译那些用我所拥有的ugilfy版本无法解析的代码。尝试使用ugifly-es而不是纯uglify包:

const uglify = require("gulp-uglify");

至:

const uglify = require("gulp-uglify-es");

并确保安装了包。

此外,如果您不想使用不受支持的软件包,请查看此answer,因为它涵盖了您的问题:

© www.soinside.com 2019 - 2024. All rights reserved.