How to solve this minification error on Gulp?

前端 未结 2 1988
既然无缘
既然无缘 2020-12-05 13:42

I\'m getting below error running this command

gulp.task(\'minify\', function () {
    return gulp
      .src(\'public/app/js/myapp.bundle.js\')
      .pipe(u         


        
相关标签:
2条回答
  • 2020-12-05 14:08

    If you run into this problem and you have in fact a transpiler step like Babel, make sure that you include the proper Babel preset in you .babelrc file. Otherwise Babel will simply leave your code as is.

    E.g.

    {
      "presets": ["es2015"]
    }
    
    0 讨论(0)
  • 2020-12-05 14:21

    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.

    Update 2017-06-17

    The branch of UglifyJS that is designed to work with ES6 is now published as uglify-es on npm.

    Update 2018-09-10

    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);
    
    0 讨论(0)
提交回复
热议问题