precompile

预处理,主要是指针对需要编译的做的处理,比如js和css和html都有更好的写法。

  • js: coffee、ts
  • css: styleus、sass、scss、postcss
  • html:各种模块,ejs、jade等,后面会单独讲

css precompile

create project

  1. nodejs-practice git:(master) express -h
  2. Usage: express [options] [dir]
  3. Options:
  4. -h, --help output usage information
  5. -V, --version output the version number
  6. -e, --ejs add ejs engine support (defaults to jade)
  7. --hbs add handlebars engine support
  8. -H, --hogan add hogan.js engine support
  9. -c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
  10. --git add .gitignore
  11. -f, --force force on non-empty directory

举例less

  1. express express-less -c less

变动

  • package.json
    • "less-middleware": "1.0.x",
  • app.js
    • app.use(require('less-middleware')(path.join(__dirname, 'public')));

创建less

  1. npm i -g less
  2. lessc public/stylesheets/style.less public/stylesheets/style.css

js precompile

举例coffee

http://coffeescript.org/

gulp