我使用Gulp合并一些 JavaScript 并对它们进行丑化。当我尝试使用 countUp 执行此操作时(也可以是其他脚本)我遇到错误。
Uncaught SyntaxError: Unexpected token 'export'
它尝试将 javascript 导出回 script 标记。现在我的 javascript 文件不仅仅是一个脚本,而是很多。
我怎样才能让它发挥作用?有没有一个工具可以将其转换为普通js,或者可能有更好的方法将其包含在gulp中?
脚本
我的 gulp 文件的一部分如下所示:
function script() {
return gulp
.src(js.src)
.pipe(concat(js.filename))
.pipe(gulp.dest(js.dest))
.pipe(uglify())
.pipe(rename({ extname: ".min.js" }))
.pipe(gulp.dest(js.dest));
}
最佳答案
您可以使用 gulp 任务将 es6 模块转换为其他类型:
const babel = require('gulp-babel'),
gulp.task('es6-commonjs',['clean-temp'], function(){
return gulp.src(['app/*.js','app/**/*.js'])
.pipe(babel({ modules: 'common' }))
.pipe(gulp.dest('dest/temp'));
});
然后在你的 gulp 管道中使用这个任务。 More info here .
关于javascript - Gulp concat、uglify 处理 ES6 导出的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60208128/