1 | # ExpressCjs [![NPM version][npm-image]][npm] [![Build Status][travis-image]][travis] [![Coverage Status][coveralls-image]][coveralls]
|
2 |
|
3 | > coffee-script / jade / stylus middleware for Single Page Application on Express4
|
4 |
|
5 | ## Quick usage
|
6 |
|
7 | ```bash
|
8 | npm install express-cjs --global
|
9 |
|
10 | mkdir my-project
|
11 | cd my-project
|
12 |
|
13 | echo "head" > index.jade
|
14 | echo " script(src='index.js')" >> index.jade
|
15 | echo " link(href='index.css' rel='stylesheet')" >> index.jade
|
16 | echo "body" >> index.jade
|
17 | echo " h1 world" >> index.jade
|
18 |
|
19 | more index.jade
|
20 | # head
|
21 | # script(src='index.js')
|
22 | # link(href='index.css' rel='stylesheet')
|
23 | # body
|
24 | # h1 world
|
25 |
|
26 | mkdir libs
|
27 |
|
28 | echo "require('./libs')" > index.coffee
|
29 | echo "console.log 'hello?'" > libs/index.coffee
|
30 |
|
31 | echo "console.log require('./libs/index.jade')" >> index.coffee
|
32 | echo "string of jade" > libs/index.jade
|
33 |
|
34 | echo "meyer-reset()" > index.styl
|
35 | echo "@import './libs/**'" >> index.styl
|
36 | echo "body{font-size:10vw}" > libs/index.styl
|
37 |
|
38 | tree .
|
39 | # my-project
|
40 | # ├── index.coffee
|
41 | # ├── index.jade
|
42 | # ├── index.styl
|
43 | # └── libs
|
44 | # ├── index.coffee
|
45 | # ├── index.jade
|
46 | # └── index.styl
|
47 |
|
48 | cjs .
|
49 | # http://localhost:59798 <- /Users/59naga/Downloads/my-project
|
50 | ```
|
51 |
|
52 | ## API
|
53 |
|
54 | ### `expressCjs({root,debug,staticServe})` -> middleware
|
55 |
|
56 | * If GET `/` to parse `/index.jade`
|
57 | * If GET `/index.js` to parse `/index.coffee` with [ng-annotate][1]
|
58 | * If GET `/index.css` to parse `/index.styl` with [kouto-swiss][2]
|
59 | * Otherwise as static serve
|
60 |
|
61 | [1]: https://github.com/olov/ng-annotate#readme
|
62 | [2]: http://kouto-swiss.io/
|
63 |
|
64 | ```js
|
65 | // Dependencies
|
66 | var express= require('express');
|
67 | var cjs= require('express-cjs');
|
68 |
|
69 | // Environment
|
70 | if(process.env.PORT===undefined){
|
71 | process.env.PORT= 59798;
|
72 | }
|
73 | var options= {
|
74 | root: process.cwd(),
|
75 | debug: process.env.NODE_ENV==='production',
|
76 | staticServe: true,// if false then disable static serve
|
77 | };
|
78 |
|
79 | // Setup & Boot
|
80 | var app= express();
|
81 | app.use(cjs(options));
|
82 | app.listen(process.env.PORT,function(){
|
83 | console.log('http://localhost:%s <- %s',process.env.PORT,options.root);
|
84 | });
|
85 | ```
|
86 |
|
87 | License
|
88 | ---
|
89 | [MIT][License]
|
90 |
|
91 | [License]: http://59naga.mit-license.org/
|
92 |
|
93 | [sauce-image]: http://soysauce.berabou.me/u/59798/express-cjs.svg
|
94 | [sauce]: https://saucelabs.com/u/59798
|
95 | [npm-image]:https://img.shields.io/npm/v/express-cjs.svg?style=flat-square
|
96 | [npm]: https://npmjs.org/package/express-cjs
|
97 | [travis-image]: http://img.shields.io/travis/59naga/express-cjs.svg?style=flat-square
|
98 | [travis]: https://travis-ci.org/59naga/express-cjs
|
99 | [coveralls-image]: http://img.shields.io/coveralls/59naga/express-cjs.svg?style=flat-square
|
100 | [coveralls]: https://coveralls.io/r/59naga/express-cjs?branch=master
|