简体   繁体   中英

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. My problem is that the code that is generated is specific to node.js

I know that traceur can be run from the browser but I wanted to optimise further. Is There a way to run traceur from the command line (node) in similar way to how lesscss works?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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