I’m using Sublime Text 2 for development on my Linux machine which has good support for CoffeeScript. If you are using Sublime Text 2 I recommend installing Package Control package manager by Will Bond and reading Using Sublime Text 2 for Development by Andy Miller. Sublime Text 2 supports TextMate bundles, to get CoffeeScript syntax highlighting just install the bundle through Package Control.
Install CoffeeScript Interpretor using your Linux distribution package manager or npm. I’m running Linux Mint 10, running my packager installer installed CoffeeScript to usr/bin. Make sure “path” is pointing to where the “coffee” executable is in your system (installing CoffeeScript using npm by running “npm install -g coffee-script” installs it to /usr/local/bin). There is no need to create a new build system file for CoffeeScript as one was created after installing the Sublime Text 2 CoffeeScript plugin. However, the path to CoffeeScript Interpretor needs to be verified before building.
After install Package Control, restart Sublime, access package control through the Command Palette using Ctrl+Shift+P. As you start typing commands, you get an overview of the available options. If you execute “discover packages” a browser pops up giving you a nice overview of all available packages and a search bar. To install a package, use command “install package”. Press enter to get a list of all available packages, type CoffeeScript, install it.
Verify Sublime CoffeeScript build file
- Open Sublime Text 2 Editor
- Preferences –> Browse Packages
- Navigate to CoffeeScript –> Commands
- Open CoffeeScript.sublime-build in Sublime
- Set “path” to the path CoffeeScript Interpretor was installed. In my case, usr/bin but your might differ.
- Save and Close
Set Build to Automatic
- Open Sublime Text 2 Editor
- Tools –> Build System –> Automatic
Create and build a simple CoffeeScript
- Open Sublime Text 2 Editor
- Create a new file by pressing Ctrl+N
- Paste the following code
1
|
|
- Save As demo.coffee
- Build by pressing Ctrl+B or F7.
- A new file will be created called demo.js in the same directory as demo.coffee.
1 2 3 4 5 6 |
|
For more information installing on Windows checkout Building CoffeeScript with Sublime on Windows by Kevin Pelgrims.