npm, nodeは事前に導入済み
$ npm install -g grunt-cli
$ mkdir hogehoge
$ cd hogehoge
$ npm init
$ npm install grunt --save-dev
$ npm install grunt-contrib-coffee --save-dev
$ npm install grunt-contrib-uglify --save-dev
$ npm install grunt-contrib-watch --save-dev
$ mkdir coffee
$ mkdir js
$ mkdir compress
Gruntfile.coffee
module.exports = (grunt) ->
pkg = grunt.file.readJSON 'package.json'
grunt.initConfig
watch:
files: ['coffee/**/*.coffee'],
tasks: ['coffee', 'uglify']
coffee:
compile:
options:
sourceMap: true
files: [
expand: true,
cwd: 'coffee/',
src: ['**/*.coffee'],
dest: 'js/',
ext: '.js'
]
uglify:
compress_target:
options:
sourceMap: (fileName) ->
fileName.replace /\.js$/, '.js.map'
files: [
expand: true,
cwd: 'js/',
src: ['**/*.js'],
dest: 'compress/',
ext: '.js'
]
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-uglify'
$ grunt watch
/coffee配下に.coffeeファイルを作成、編集すると自動的にコンパイル&圧縮する