Sea.js Manual & Documentation


Table of Contents


Coffee Plugin

CoffeeScript is a little language that compiles into JavaScript. Underneath all of those embarrassing braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

With SeaJS, it is easy to code in CoffeeScript in the browser. Let's take an example.

First, using seajs.config to specify the path of coffee script compiler and enable the coffee plugin by adding it to preload:

seajs.config({
  alias: {
    'coffee': 'coffee/1.1.2/coffee-script'
  },
  preload: ['plugin-coffee']
});

Then, just write your coffee script files, and load them using require:

a.coffee:

define (require, exports) ->
  exports.foo = 'bar'
  return

main.js:

define(function(require) {
  var a = require('./a.coffee');
  console.log(a.foo);
});

There is no more words of explanation.

Please see the online example: Coffee and LESS in SeaJS