简体   繁体   English

如何为浏览器编译ES5代码到ES5?

[英]How can I compile ES6 code to ES5 for the browser?

I have installed traceur using npm and have managed to compile a simple ES6 script. 我已经使用npm安装了traceur并且设法编译了一个简单的ES6脚本。 My problem is that the code that is generated is specific to node.js 我的问题是生成的代码特定于node.js

I know that traceur can be run from the browser but I wanted to optimise further. 我知道traceur可以从浏览器运行,但我想进一步优化。 Is There a way to run traceur from the command line (node) in similar way to how lesscss works? 有没有办法从命令行(节点)运行traceur,方式与lesscss的工作方式类似?

I might be a bit late to the party, and you already found the solution as mentioned in your comment, but still I want to give an answer to make it easier for others to find the solution. 我可能有点迟到了,你已经找到了你的评论中提到的解决方案,但我仍然想给出答案,让其他人更容易找到解决方案。

It's possible to compile your ES6 code with adding --script to your command. 可以通过在命令中添加--script来编译ES6代码。

Compile a single file 编译单个文件

$ traceur es6-code.js --script es5-code.js

Compile multiple files to a single file 将多个文件编译为单个文件

$ traceur --out es6-code-1.js es6-code-2.js es6-code-3.js --script es5-code.min.js

Read more in Compiling Offline and Options for Compiling in the Traceur wiki. 阅读Traceur wiki中的编译离线编译 选项的更多内容。

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

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