Many people prefer CoffeeScript to the standard JavaScript syntax. If you are one of those people with a preference, Meteor has you covered. This recipe will show you how to quickly enable CoffeeScript in your development environment.
Nothing is needed to prepare for this recipe, other than having Meteor installed, and a project created so that you can begin using CoffeeScript.
To use CoffeeScript, proceed with the following steps:
Open a terminal window and navigate to the root folder of your project.
Enter the following command:
$ meteor add coffeescript
You should see the following response in the terminal window:
coffeescript added, version 1.0.
CoffeeScript is now installed and ready to go!
You can test the installation by creating a .coffee
file and adding a script (for example, add test.coffee
to your client
folder). When you start your Meteor application with the meteor
command, the script should execute as designed.
Behind the scenes, the CoffeeScript package you just installed looks for any and all *.coffee
and *.litcoffee
files, compiles them into native JavaScript, and then bundles them for use in your running Meteor application.
The Adding Meteor packages recipe in Chapter 2, Customizing with Packages