使用 grunt来编译coffee 文件.
访问量: 3445
refer to: https://github.com/gruntjs/grunt-contrib-coffee
and: http://siwei.me/blog/posts/grunt-using-grunt-to-speed-up-your-js-development
npm install: grunt , grunt-cli, grunt-contrib-coffee
$ npm install grunt-contrib-coffee --save-dev
编辑: Gruntfile.coffee:
module.exports = (grunt) ->
grunt.initConfig
coffee:
compile_multiple_files:
options:
bare: true
files:
# 1:1 的编译文件
#'app/controllers/simulate_stocks.js': 'app/controllers/simulate_stocks.coffee'
# 编译多个文件
[
expand: true
flatten: true
cwd: 'app/controllers/'
src: ['*.coffee']
dest: 'app/controllers/'
ext: '.js'
]
compile_home_js:
options:
bare: true
files:
# 把多个文件合并
'app/controllers/home.js': [
'app/controllers/home/home_market.coffee'
'app/controllers/home/home_master.coffee'
'app/controllers/home/home_me.coffee'
'app/controllers/home/home_competition.coffee'
'app/controllers/home/home_community.coffee'
'app/controllers/home/home_version.coffee'
'app/controllers/home/home_frame.coffee'
]
#grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.registerTask 'default', [ 'coffee' ]
然后运行: $ grunt
就会把 coffee的所有 子任务 (sub- tasks) 都依次运行了. 结果如下;
$ grunt Running "coffee:compile_multiple_files" (coffee) task >> 53 files created. Running "coffee:compile_home_js" (coffee) task >> 1 files created. Done, without errors.