[英]Browserify ES6 code without gulp
I'm using browserify with ES5 code 我使用browserify与ES5代码
$> browserify index.js > bundle.js
But now I would like to do the same thing with ES6. 但是现在我想对ES6做同样的事情。 With gulp this is easy: 使用gulp,这很容易:
gulp.task('build', function () {
return browserify(....)
.transform(babelify)
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('dist'));
});
Is it possible to use this command line tool to handle ES6 code ? 是否可以使用此命令行工具来处理ES6代码?
UPDATE: 更新:
Here are the files from my test project: 这是我的测试项目中的文件:
index.js: index.js:
import test from 'test';
test();
test.js: test.js:
export default function doit(msg = 'default msg') {
alert(`x: ${msg}`);
}
index.html: index.html:
<!doctype html>
<html>
<head><head>
<body>
<script src="bundle.js"></script>
</body>
<html>
Now If I run the suggested command: 现在,如果我运行建议的命令:
$> browserify index.js -o bundle.js -t babelify --presets es2015
index.js:1
import test from 'test';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Any suggestions what I'm doing wrong ? 有什么建议我做错了吗?
试试吧:
browserify -t [ babelify --presets [ es2015 ] ] origin.js -o destination.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.