简体   繁体   English

使用babel.js代替browserify编译为bundle

[英]Using babel.js instead of browserify to compile to bundle

I am starting out with babel.js to make use of JavaScript ES6 features, however I have run in to a problem 我开始使用babel.js来使用JavaScript ES6功能,但是我遇到了一个问题

I am currently building my app using browserify and reactify with the following command. 我目前正在使用browserify构建我的应用程序并使用以下命令重新执行。

browserify -t reactify app/main.js -o public/scripts/bundle.js

Now I want to use an equivalent command in babel to bundle up my required modules, written in ES6 to a bundle.js . 现在我想在babel中使用一个等效命令将我需要的模块捆绑在一起,用ES6编写一个bundle.js This doesn't work, just giving me an ES5 version of the main.js file. 这不起作用,只给我一个ES5版本的main.js文件。

babel app/main.js -o public/scripts/bundle.js

However I could compile my bundle.js file to an ES6 version with babel, having 2 commands 但是我可以将我的bundle.js文件编译成带有babel的ES6版本,有2个命令

browserify -t reactify app/main.js -o public/scripts/bundle.js
babel app/main.js -o public/scripts/babel.js

Is this the correct way to use babel with browserify? 这是使用browserify使用babel的正确方法吗? to bundle your modules with browserify and then convert the bundle to ES6? 使用browserify捆绑您的模块,然后将捆绑包转换为ES6?

Nope, the correct way is to use babelify. 不,正确的方法是使用babelify。

# from
browserify -t reactify app/main.js -o public/scripts/bundle.js
# to
browserify -t babelify app/main.js -o public/scripts/bundle.js

Also the reactify/react-tools/jsx-loader/etc. 还有reactify / react-tools / jsx-loader / etc. tools from the react team do a subset of what babel does, so you can remove them entirely if you're using babel. 反应团队的工具做了巴贝尔所做的一部分,所以如果你使用巴贝尔,你可以完全删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM