这是我的gulpfile中的一部分:

gulp.task('compile-js', function () {
    // app.js is your main JS file with all your module inclusions
  return browserify({
    extensions: ['.js', '.jsx'],
    entries: 'javascripts/app.js',
    debug: true
  })
  .transform('babelify', { presets: ['es2015', 'react'] })
  .bundle()
  .pipe(source('bundle.min.js'))
  .pipe(buffer())
  .pipe(sourcemaps.init())
  .pipe(uglify())
  .pipe(sourcemaps.write('./maps'))
  .pipe(gulp.dest('dist'))
  .pipe(livereload())
})


在我的javascripts/app.js中:

我有一个例子:

async function write () {
    var txt = await read();
    console.log(txt);
  }


我收到此错误:

GulpUglifyError: unable to minify JavaScript


这是我的package.json的一部分:

  "dependencies": {
    "animate.css": "^3.5.2",
    "aos": "^2.2.0",
    "autosize": "^4.0.0",
    "axios": "^0.16.2",
    "es6-docready": "^1.0.0",
    "foundation-icon-fonts": "^0.1.1",
    "foundation-sites": "^6.4.3",
    "gulp-clean-css": "^3.9.0",
    "gulp-cssimport": "^5.1.1",
    "jquery": "^3.1.1",
    "jquery-ui-bundle": "^1.12.1",
    "material-design-icons": "^3.0.1",
    "swiper": "^3.4.2",
    "vue": "^2.4.4"
  },
  "repository": {
    "type": "git",
    "url": "[git-url-of-your-project]"
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-react": "^6.16.0",
    "babelify": "^7.3.0",
    "browserify": "^14.3.0",
    "browserify-shim": "^3.8.12",
    "gulp": "^3.9.1",
    "gulp-clean-css": "^3.0.4",
    "gulp-clone": "^1.0.0",
    "gulp-concat": "^2.6.0",
    "gulp-concat-css": "^2.3.0",
    "gulp-cssimport": "^5.0.0",
    "gulp-foreach": "^0.1.0",
    "gulp-htmlmin": "^3.0.0",
    "gulp-less": "^3.3.2",
    "gulp-livereload": "^3.8.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-uglify": "^2.1.2",
    "streamqueue": "^1.1.1",
    "vinyl-buffer": "^1.0.0",
    "vinyl-source-stream": "^1.1.0"
  },


我应该在ES6的gulp流程中添加什么?

编辑:

因此请遵循es2017的babel doc

我已经安装了:

npm install --save-dev babel-preset-es2017


并更改了我的gulpfile:

...
.transform('babelify', {
    presets: ['es2015', 'es2017', 'react'],


我在编译过程中没有收到任何错误,但是在浏览器中运行代码时却在浏览器控制台上收到了此错误:

Uncaught ReferenceError: regeneratorRuntime is not defined

最佳答案

gulp-uglify也有类似的问题,正如我发现的那样,基本gulp-uglify不支持最小化异步/等待,所以我切换到babel-minify,它对我有用。

编辑:对于regeneratorRuntime is not defined错误,我认为regenerator-runtime可能会有所帮助。

10-06 12:28