You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
arindam89 edited this page Feb 26, 2015
·
1 revision
How to use the traceur to compile to JavaScript files from the command line.
Traceur includes a shell script traceur to let you compile JavaScript code with ES6 and Traceur experimental features down to vanilla ES5. To use the generated file you will need to include a runtime file (bin/traceur-runtime.js). This runtime file contains polyfills as well as helper functions which reduce the generated code size.
Compiling Files
First, make sure you have Node installed. Then create a Javascript file with some ES6 features extensions in it. For example:
This will create an out/ directory containing greeter.js which has all ES6 features compiled to plain ES5 JavaScript.
By default, the input files to the command line compiler are treated as anonymous modules, and thus get wrapped. If you want to treat these files as script (global code) use one or more --script <filename> command line flags.
Using Compiled Files
We can test the greeter.js we just compiled with a minimal HTML page like:
<html><head><scriptsrc="bin/traceur-runtime.js"></script><scriptsrc="out/greeter.js"></script></head><body>
You should see "Hi Anonymous!" in your console.
</body></html>