运行此命令时遇到错误
gulp.task('minify', function () {返回一口.src('public/app/js/myapp.bundle.js').pipe(丑化()).pipe(gulp.dest('public/app/js/myapp.bundle.min.js'));});<块引用>
GulpUglifyError: 无法缩小 JavaScript 原因:SyntaxError: Unexpected token: name (MenuItem) (line: 1628, col: 18, pos: 53569)
该位置的代码是这样的
设置器:[],执行:函数(){class MenuItem {//<-- 第 1628 行怎么了?
UglifyJS 目前不支持 EcmaScript 6 结构 类似类.
您可能需要首先通过转译器步骤运行您的 JavaScript,或者找到一个知道如何处理 ES6 代码的压缩程序.
设计用于 ES6 的 UglifyJS 分支现已发布为 uglify-es 在 npm 上.
terser 是新的 uglify-es,uglify-es 不再维护.
如果使用 gulp 两个 npmjs gulp-uglify-es 和 npmjs gulp-terser 软件包支持 terser.
npm install gulp-terser --save-devconst gulp = require('gulp');const terser = require('gulp-terser');函数 es(){返回 gulp.src('./src/index.js').pipe(terser()).pipe(gulp.dest('./build'))}gulp.task('default', es);I'm getting below error running this command
gulp.task('minify', function () {
return gulp
.src('public/app/js/myapp.bundle.js')
.pipe(uglify())
.pipe(gulp.dest('public/app/js/myapp.bundle.min.js'));
});
GulpUglifyError: unable to minify JavaScript Caused by: SyntaxError: Unexpected token: name (MenuItem) (line: 1628, col: 18, pos: 53569)
Code on that location is this
setters: [],
execute: function () {
class MenuItem { // <-- line 1628
What's wrong?
UglifyJS does not currently support EcmaScript 6 structures like classes.
You'll probably need to run your JavaScript through a transpiler step first, or find a minifier that knows what to do with ES6 code.
The branch of UglifyJS that is designed to work with ES6 is now published as uglify-es on npm.
terser is the new uglify-es, uglify-es is no longer maintained.
If using gulp both npmjs gulp-uglify-es and npmjs gulp-terser packages support terser.
npm install gulp-terser --save-dev
const gulp = require('gulp');
const terser = require('gulp-terser');
function es(){
return gulp.src('./src/index.js')
.pipe(terser())
.pipe(gulp.dest('./build'))
}
gulp.task('default', es);
这篇关于如何解决 Gulp 上的这个缩小错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Browserify,Babel 6,Gulp - 传播运算符上的意外令牌Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 传播运算符上的意外令牌)
是否可以将标志传递给 Gulp 以使其以不同的方式Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以将标志传递给 Gulp 以使其以不同的方式运行任务
为什么我们需要在全局和本地安装 gulp?Why do we need to install gulp globally and locally?(为什么我们需要在全局和本地安装 gulp?)
如何一个接一个地依次运行 Gulp 任务How to run Gulp tasks sequentially one after the other(如何一个接一个地依次运行 Gulp 任务)
由于 MIME 类型而未加载样式表Stylesheet not loaded because of MIME-type(由于 MIME 类型而未加载样式表)
打开 Javascript 文件时 Visual Studio 2015 崩溃Visual Studio 2015 crashes when opening Javascript files(打开 Javascript 文件时 Visual Studio 2015 崩溃)