0.2.1 • Published 9 years ago

connect-coffee-script v0.2.1

Weekly downloads
223
License
BSD-3-Clause
Repository
github
Last release
9 years ago

Build Status

connect-coffee-script

It provide a simple Connect middleware to serve CoffeeScript files. It is modeled after the Stylus middleware.

This project was created after the drop of native support for CoffeeScript in latest Express. More specifically, Express droped the compiler middleware in its versions 2 and 3 (the current versions at the time of this writing).

Read the annoucement article for more information.

Installation

Using npm:

npm install connect-coffee-script

Usage

Function returning a Connect middleware with the given options.

Options:

  • force Always re-compile
  • src Source directory used to find .coffee files
  • dest Destination directory used to output .js files when undefined defaults to src
  • compile Custom compile function, accepting the arguments (str, options)
  • bare Compile without a top-level function wrapper
  • baseDir Base directory for path resolution
  • newPrefix Use the new declaration (//# instead of //@)
  • prefix Path which should be stripped from src
  • sourceMap Generates source map files
  • sourceMapRoot but added back to the sourceMap url.

Basic example

Here we will setup the middleware with only the required src option.

var coffeescript = require('connect-coffee-script');
var connect = require('connect');

var app = connect();

app.use(coffeescript({
  src: __dirname,
  bare: true
}));

app.use(connect.static(__dirname + '/public'));

app.listen(3000)

Advanced example

Here we set up the custom compile function so that we may set the bare option, or define additional functions.

By default the compile function simply renders the JavaScript.

function compile(str, options, coffeePath) {
  options.bare = true;
  return coffeeScript.compile(str, options);
}

Pass the middleware to Connect, grabbing "*.coffee" files from this directory and saving .js files to ./public. Also supplying our custom compile function.

Following that we have a static() layer setup to serve the .js files generated by CoffeeScript.

var coffeeScript = require('coffee-script');
var connectCoffeescript = require('connect-coffee-script');
var connect = require('connect');

var app = connect();

app.use(connectCoffeescript({
  src: __dirname,
  dest: __dirname + '/public',
  compile: compile
}));

app.use(connect.static(__dirname + '/public'));

Contributors

0.2.1

9 years ago

0.2.0

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.1

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago