A really great feature of Sublime Text 2 is the ability to create your own build scripts. A build script is helpful when you are writing in a language that needs to be compiled or executed from terminal / command line. I personally use build scripts to compile the current file into CoffeeScript as well as run the current file in Node JS.
Watch the tutorial or continue reading to learn how to make Sublime Text 2 build scripts.
https://youtu.be/iejQvQF-vZo
To get started, go to Tools->Build System -> New Build System...
and you will be presented with the boilerplate for a build script.
We have four lines to feed into our .sublime-build
file:
* **cmd** is an array of commends that will be run.*
For a complete list of all the variables available within a build script, check the variable reference.
So, to create our CoffeeScript build file, we simply fill in the following three lines. Keep in mind that with the Node.js coffeescript compiler we would normally execute something similar to this in the terminal:
coffee -c /path/to/file.coffee
{
"cmd": ["coffee","-c", "$file"],
"selector" : "source.coffee",
"path" : "/usr/local/bin"
}
Save your file in your user packages folder and restart Sublime Text. On OSX its located at: ~/Library/Application Support/Sublime Text 2/Packages/User
Now every time we hit CMD + B our coffeescript file will be compiled with the build script. If you want to watch the file for changes after the first compile, simply switch the first line to "cmd": ["coffee","-wc", "$file"],. If anyone is using my <a href="https://github.com/wesbos/coffeescript-growl" target="_blank">CoffeeScript-Growl plugin</a>, change your first line to "cmd": ["coffee", "-r", "coffeescript-growl", "-wc", "$file"],
to get growl notifications.
Another use for Sublime Text build scripts is launching the nodejs file you are currently working on. Our build script now looks something like this:
{
"cmd": ["node", "$file"],
"selector" : "source.js",
"path" : "/usr/local/bin"
}
Pretty simple, eh? There is a lot of room for expanding these builds and making them do a lot of the manual work for you. If you have anything to add, please post it in the comments and I'll be sure to add it to the post.
As always be sure to Follow me on Twitter
Find an issue with this post? Think you could clarify, update or add something?
All my posts are available to edit on Github. Any fix, little or small, is appreciated!