Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 526
thomas-peter Avatar asked Nov 10 '22 08:11

thomas-peter


1 Answers

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.

like image 164
morkro Avatar answered Nov 14 '22 22:11

morkro