简体   繁体   English

在生产中使用Babel的正确方法

[英]Proper way to use Babel in production

I want to use babel to transform modern javascript to plain old ES5 JavaScript. 我想使用babel将现代javascript转换为普通的旧ES5 JavaScript。

I used the first tool on babel 's website "Prototyping-In the browser" and on the website it says 我在babel的网站“Prototyping-In the browser”和网站上使用了第一个工具

"... if you are working on a production site you should be precompiling your scripts server-side" “......如果您正在生产站点上工作,那么您应该预先编译脚本服务器端”

after using that prototyping tool, the browser's console says 使用该原型工具后,浏览器的控制台说

"... Be sure to precompile your scripts for production" “...请务必预编译脚本以进行制作”

as a result I checked the second tool "Babel built-ins CLI" and used it with the help of node.js to generate the compatible JS scripts, the website doesn't mention the same message about production as the first tool I used, although the resulting code is almost the same. 结果我检查了第二个工具“Babel built-ins CLI”并在node.js的帮助下使用它来生成兼容的JS脚本,网站没有提到与我使用的第一个工具相同的生产信息,虽然结果代码几乎相同。

My question is can I grab the resulting JS scripts from the "Babel CLI" tool and just replace the current ones? 我的问题是,我可以从“Babel CLI”工具中获取生成的JS脚本,只需替换当前的脚本吗? is that enough for production? 是否足以生产? Are they considered precompiled? 它们被认为是预编译的吗?

Note that I am not using node.js, it is just a javascript application. 请注意,我没有使用node.js,它只是一个javascript应用程序。

Searching around the web got me many results about precompiling JS such as using webpack and Browserify and now I am lost about the state of the files generated from Babel, are they ready to be used or should they be precompiled. 在网上搜索得到了很多关于预编译JS的结果,比如使用webpack和Browserify,现在我对从Babel生成的文件的状态感到迷茫,它们是否可以使用或者是否应该进行预编译。

I am posting this question out of confusion, so my apologies if it sounds stupid or not reasonable. 我发布这个问题是出于混乱,所以如果它听起来很愚蠢或不合理,我会道歉。

Can I grab the resulting JS scripts from the "Babel CLI" tool and just replace the current ones? 我可以从“Babel CLI”工具中获取生成的JS脚本,只需替换当前的脚本吗? Is that enough for production? 这对生产来说足够了吗?

Yes, that would work. 是的,那会有用。 However you will want to avoid this manual step of copying scripts into a web tool for every little change you make during development. 但是,您需要避免将脚本复制到Web工具中的手动步骤,以便在开发过程中进行每一处小改动。 It's better to work with an automated build flow. 最好使用自动构建流程。

Searching around the web got me many results about precompiling JS such as using webpack and Browserify 在网上搜索得到了很多关于预编译JS的结果,比如使用webpack和Browserify

Babel only transpiles new syntax to old syntax. Babel只会将新语法转换为旧语法。 Webpack and Browserify also bundle modules into a single script that can be loaded into a webpage. Webpack和Browserify还将模块捆绑到一个可以加载到网页中的脚本中。

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

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