Gruntの環境を作ってみる

ちょっとだけJavaScriptを書く機会ができたから、せっかくなのでCoffeeScriptで書こうと思ってGrunt環境の作り方を調べた。 クソ適当なメモ。

mkdir hoge
cd hoge
ndenv install v0.11.14
ndenv rehash
ndenv local v0.11.14
npm install -g grunt-cli
npm init
npm install grunt --save-dev
npm install grunt-contrib-watch --save-dev
npm install grunt-contrib-coffee --save-devo
vim Gruntfile.coffee

Gruntfile.coffeeの中身

module.exports = (grunt) ->
  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'
    watch:
      coffee:
        files: ['coffee/**/*.coffee']
        tasks: 'coffee::app'
    coffee:
      app:
        files: [
          expand: true
          cwd: 'coffee/'
          src: ['**/*.coffee']
          dest: 'htdocs/js/'
          ext: '.js'
        ]

  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-watch'
  grunt.registerTask 'default', ['watch']
  return

これだけ設定すれば、gruntでwatchに入れる。 あとは好きなだけCoffeeScriptを書くよろし。