如何在不转译异步功能的情况下与Browserify和Babelify捆绑在一起?

时间:2019-04-27 10:59:50

标签: gulp browserify babel babelify

当我将Babel设置为在源中保留异步功能时,构建任务将失败。

我正在通过env-preset配置Babel。目标ios >= 11失败了,而ios >= 10.3的构建很好了,因为异步函数被编译了。

我的gulp文件:

"use strict";
/*eslint-env node */

const gulp = require("gulp");
const browserify = require("browserify");
const babelify = require("babelify");
const source = require("vinyl-source-stream");

gulp.task("scripts", function() {
  const bundle = browserify({ entries: ["./src/scripts/index.js"] })
    .transform(
      babelify.configure({
        presets: [
            ["@babel/preset-env", { targets: { browsers: "ios >= 11" } }],
        ],
      })
    )
    .bundle()
    ;

  return bundle
    .pipe(source("app.min.js"))
    .pipe(gulp.dest("./dist/scripts/"))
    ;
});

版本:

node v10.15.3
@babel/core ^7.4.4
@babel/preset-env ^7.4.4
babelify ^10.0.0
browserify ^16.2.3
gulp ^4.0.1
vinyl-source-stream ^2.0.0

输出包应使用本机Async函数,但构建任务将失败:

const runPureTask = async task => {
                          ^
ParseError: Unexpected token
    at formatError (/.../node_modules/gulp/node_modules/gulp-cli/lib/versioned/^4.0.0/format-error.js:21:10)
    at Gulp.<anonymous> (/.../node_modules/gulp/node_modules/gulp-cli/lib/versioned/^4.0.0/log/events.js:33:15)
    at Gulp.emit (events.js:194:15)
    at Gulp.EventEmitter.emit (domain.js:441:20)
    at Object.error (/.../node_modules/undertaker/lib/helpers/createExtensions.js:61:10)
    at handler (/.../node_modules/now-and-later/lib/map.js:50:14)
    at f (/.../node_modules/once/once.js:25:25)
    at f (/.../node_modules/once/once.js:25:25)
    at tryCatch (/.../node_modules/async-done/index.js:24:15)
    at done (/.../node_modules/async-done/index.js:40:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! interfaces@1.0.0 start: `gulp "scripts"`

0 个答案:

没有答案