我的gulp配置文件基礎是這樣的。const gulp = require('gulp'),
babel = require('gulp-babel'),
ugify = require('gulp-uglify')
gulp.task('watch', function () {
gulp.watch('app.js', ['a'])
})
gulp.task('a', () =>
gulp.src('app.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(ugify())
.pipe(gulp.dest('dist'))
)然后我的app.js中用了es6的module語法import { bar } from './index.js'var foo = () => { console.log(bar)
}
foo()index.js如下export const bar = 'aaaaaaaaaaaa'打包后的js如下,但是這樣并不能在瀏覽器端運行。"use strict";var _index=require("./index.js"),foo=function(){console.log(_index.bar)};foo();所以,應該怎么修改呢。
gulp怎么打包js中的import語法
天涯盡頭無女友
2018-11-21 17:13:42