UNPKG

2.64 kBMarkdownView Raw
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
8npm install express-cjs --global
9
10mkdir my-project
11cd my-project
12
13echo "head" > index.jade
14echo " script(src='index.js')" >> index.jade
15echo " link(href='index.css' rel='stylesheet')" >> index.jade
16echo "body" >> index.jade
17echo " h1 world" >> index.jade
18
19more index.jade
20# head
21# script(src='index.js')
22# link(href='index.css' rel='stylesheet')
23# body
24# h1 world
25
26mkdir libs
27
28echo "require('./libs')" > index.coffee
29echo "console.log 'hello?'" > libs/index.coffee
30
31echo "console.log require('./libs/index.jade')" >> index.coffee
32echo "string of jade" > libs/index.jade
33
34echo "meyer-reset()" > index.styl
35echo "@import './libs/**'" >> index.styl
36echo "body{font-size:10vw}" > libs/index.styl
37
38tree .
39# my-project
40# ├── index.coffee
41# ├── index.jade
42# ├── index.styl
43# └── libs
44# ├── index.coffee
45# ├── index.jade
46# └── index.styl
47
48cjs .
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
66var express= require('express');
67var cjs= require('express-cjs');
68
69// Environment
70if(process.env.PORT===undefined){
71 process.env.PORT= 59798;
72}
73var 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
80var app= express();
81app.use(cjs(options));
82app.listen(process.env.PORT,function(){
83 console.log('http://localhost:%s <- %s',process.env.PORT,options.root);
84});
85```
86
87License
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