Coder Social home page Coder Social logo

focusaurus / node-connect-coffee-script Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adaltas/node-connect-coffee-script

0.0 2.0 0.0 104 KB

Connect middleware to serve CoffeeScript files

Home Page: http://www.adaltas.com/blog/2012/07/24/coffee-script-connect-middleware/

CoffeeScript 87.99% JavaScript 12.01%

node-connect-coffee-script's Introduction

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

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) {
    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

node-connect-coffee-script's People

Contributors

davewasmer avatar focusaurus avatar wdavidw avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.