Compile JavaScript in your Sublime Text 3 Editor

So I was going through tutorials on JavaScript loops and such. I needed to find a better way of compiling my JavaScript to streamline the whole process. So I looked into a build process for JS within the text editor, I already had one in place to launch the webpage in Chrome but nothing for a standalone JS file.

First I will get you to make sure you are up to date with the latest JS interpreter. I installed the EcmaScript6 node package that you can find here. Unless you are pointing at a package nothing will happen. On a Mac this is installed into the folder /usr/local/bin/iojs

So go to your Sublime Text 2 editor and select Tools > Build System > New Build System...
You will be presented with a boilerplate looking JSON object, replace that object with the following:

Mac Users:

"cmd": ["/usr/local/bin/iojs", "$file"],
"selector": "source.js"

Windows Users:

  "cmd": ["C:/Program Files/nodejs/node.exe", "$file"],
  "selector": "source.js"

Save this as JavaScript.sublime-build, select it in your Tools > Build System options in Sublime and run CMD B.
In-Editor JS Compiling
Eh voila, no more switching between editor and browser to see it something is working.

Leave a Reply

Your email address will not be published. Required fields are marked *