Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the connect middleware for coffeescript?

Yes I know connect-assets. But I hope the coffeescript files can be compiled on request. Just like in stylus middleware.

app.use(stylus.middleware(
  src: __dirname + "/assets",
  dest: __dirname + "/public"
))

So... is there anything that works this way?

EDIT: I know connect.compiler too. But it has been removed in newest version of connect.

like image 637
Lai Yu-Hsuan Avatar asked Jul 18 '12 20:07

Lai Yu-Hsuan


People also ask

What is Connect middleware?

Connect is an extensible HTTP server framework for node, providing high performance "plugins" known as middleware. More specifically, connect wraps the Server, ServerRequest, and ServerResponse objects of node.

What is CoffeeScript written in?

CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Specific additional features include list comprehension and destructuring assignment.

How do I use CoffeeScript in HTML?

You simple need to add a <script type="text/coffeescript" src="app. coffee"></script> to execute coffee script code in an HTML file. In other cases, I've seen people use the attributes of type="coffeescript" and type="coffee" , so they might work for you as well. Save this answer.


2 Answers

I've just published a new module, npm install connect-coffee-script, which does just that. Documentation and a sample are provided as well as an introduction article.

Here's an exemple from the readme:

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

    var app = connect();

    app.use(coffeescript({
        src: __dirname,
        dest: __dirname + '/public',
        bare: true
    }));

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

    app.listen(3000)
like image 177
wdavidw Avatar answered Sep 25 '22 07:09

wdavidw


app.use(express.compiler({
  src: __dirname + "/assets",
  dest: __dirname + "/public",
  enable: ['coffeescript']
}));

could also add stylus to the enable array if you are using both!

im using express 2.5.9

like image 28
Adam Avatar answered Sep 21 '22 07:09

Adam