使用Gulp绑定供应商文件

使用Gulp绑定供应商文件,gulp,syntax-error,Gulp,Syntax Error,我正在尝试使用gulp从供应商处分离源代码。在当前状态下,我的gulpfile.js就是这样设置的: gulpfile.js ///////////// LIBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ var gulp = require('gulp'); var browserSync = require('browser-sync').create(); var superstatic = require('superstatic');

我正在尝试使用
gulp
从供应商处分离源代码。在当前状态下,我的
gulpfile.js
就是这样设置的:

gulpfile.js

/////////////       LIBS        \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var superstatic = require('superstatic');
var gulpTsc = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var tsConfigGlob = require('tsconfig-glob');
var browserify = require('browserify');
var path = require('path');
var child_process = require('child_process');
var del = require('del');
var sourceStream = require('vinyl-source-stream');

// other tasks

var bundleVendorFiles = function(done) {
var deps = Object.keys(ngPkgFile && ngPkgFile.dependencies || {});
deps.map(d => {
    let posOfAt = d.indexOf('@'),
        modName = `${angularAppLocation}/node_modules/`,
        exposeName = d;
    if(posOfAt < 0) modName += d;
    else modName += `@angular/${d.split('/').pop()}`;
    return {
        file: modName,
        expose: exposeName
    };    
});
browserify({
    paths: [angularAppLocation+'/node_modules'],
    basedir: '/home/zerocool/srs-demo/loginapp'
})
    .require(deps)
    .transform("babelify", { presets: ["es2015"]})
    .bundle()
    .pipe(sourceStream('vendor.bundle.js'))
    .pipe(gulp.dest(angularAppLocation+'/dist'));
done();
};

gulp.task('default', gulp.series([
'clean-dist-dir', 'copy-index-file', 'expand-file-glob',
'ts-compile', 'bundle-vendor-pkgs',/*
'copy-static-assets', 'copy-misc-asset-files'*/
]));

我在这个
gulpfile
中缺少了什么?除了
gulpfile
,我还需要其他设置吗?我是新来的
gulp
,因此,如果需要更多信息,请询问。谢谢,这意味着你的js没有被babelify正确传输

试一试

确保通过
npmi--save dev@babel/core@babel/preset env下载这些包依赖项

[02:31:16] Using gulpfile ~/srs-demo/gulpfile.js
[02:31:16] Starting 'default'...
[02:31:16] Starting 'clean-dist-dir'...
[02:31:16] Finished 'clean-dist-dir' after 9.41 ms
[02:31:16] Starting 'copy-index-file'...
[02:31:16] Finished 'copy-index-file' after 13 ms
[02:31:16] Starting 'expand-file-glob'...
[02:31:16] Finished 'expand-file-glob' after 38 ms
[02:31:16] Starting 'ts-compile'...
[02:31:16] Finished 'ts-compile' after 407 ms
[02:31:16] Starting 'bundle-vendor-pkgs'...
[02:31:16] Finished 'bundle-vendor-pkgs' after 29 ms
[02:31:16] Finished 'default' after 501 ms

events.js:112
  throw er; // Unhandled 'error' event
  ^
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
browserify({
    paths: [angularAppLocation+'/node_modules'],
    basedir: '/home/zerocool/srs-demo/loginapp'
})
    .require(deps)
    .transform(babelify.configure({presets: ["@babel/preset-env"]}))
    .bundle()
    .pipe(sourceStream('vendor.bundle.js'))
    .pipe(gulp.dest(angularAppLocation+'/dist'));
done();
};