Setting Up Ember CLI with CoffeeScript

Ember CLI is a powerful command line utility for Ember.js. By default, Ember CLI generates JavaScript files for your ember application. However, you can enable CoffeeScript easily.

Create a new Ember CLI application:

$ ember new my-new-app

Next, install ember-cli-coffeescript addon.

$ ember install ember-cli-coffeescript

Note: This addon requires Ember CLI version more than 0.2.0.

Let’s modify the app.js to app.coffee

`import Ember from 'ember'`
`import Resolver from 'ember/resolver'`
`import loadInitializers from 'ember/load-initializers'`
`import config from './config/environment'`

Ember.MODEL_FACTORY_INJECTIONS = true

App = Ember.Application.extend
  modulePrefix: config.modulePrefix
  podModulePrefix: config.podModulePrefix
  Resolver: Resolver

loadInitializers(App, config.modulePrefix)

`export default App`

We are almost done. Now, let’s modify router.js to router.coffee.

`import Ember from 'ember'`
`import config from './config/environment'`

Router = Ember.Router.extend
  location: config.locationType

Router.map ->

`export default Router;`

Lastly, run ember server. You should see “Welcome to Ember.js”. The next time you use ember generate command, all files will be generated in CoffeeScript.

Now, you can start working on your ambitious web application using CoffeeScript!

Useful ES6 Features

Useful ES6 Features for Javascript developer Continue reading