How to minify ES6 functions with gulp-uglify?

后端 未结 8 1198
时光说笑
时光说笑 2020-12-23 11:23

When I run gulp I get the following error:

[12:54:14] { [GulpUglifyError: unable to minify JavaScript]
cause:
{ [SyntaxError: Unexpected token: operator (>         


        
8条回答
  •  醉酒成梦
    2020-12-23 11:56

    gulp-uglify:

    For ES6 and newer.

    1. install: npm install --save-dev gulp-uglify
    2. install: npm install --save-dev gulp-babel @babel/core @babel/preset-env

    Usage:

    const gulp = require('gulp'); 
    const uglify = require('gulp-uglify');
    const babel = require('gulp-babel');
    
    gulp.task('script', () => {
        return gulp.src('src/**/*.js')
            .pipe(babel({
                presets: ['@babel/env']
            }))
            .pipe(uglify())
            .pipe(gulp.dest('src/dist'))
    });
    

提交回复
热议问题