LoginSignup
5
5

More than 5 years have passed since last update.

grunt のバージョン上げずにタスクを CoffeeScript でかく

Last updated at Posted at 2013-02-04

grunt

http://gruntjs.com/

HTML / JS / CSS 関係のファイルをコンパイルしたり結合したりぺちゃんこにしたり
テストしたり git にコミットしてくれたりプラグイン次第で色々してくれる便利ツール。
node.js 上で動く。

不満

安定版のバージョン0.3はタスクを JS で書く。
複雑なタスクを書くと {} のネストがひどい。

開発版のバージョン0.4はタスクを CoffeeScript で書けるけど、
対応していないプラグインがある。

grunt の0.3を使いつつ coffee でタスクを書きたい。

解決法

~/.bashrc に以下を追記

alias grunt='coffee -bc grunt.coffee;\grunt'

読み込みましょう

source ~/.bashrc

するとこれが

module.exports = function(grunt) {
    grunt.initConfig({

        lint: {
            all: [
                'grunt.js',
                'lib/**/*.js',
                'test/**/*.js'
            ]
        },

        jshint: {
            options: {
                browser: true
            }
        }
    });

    grunt.loadNpmTasks('grunt-sample');
    grunt.registerTask('default', 'lint sample');
};

これに

module.exports = (grunt) ->
    grunt.initConfig

        lint:
            all: [
                'grunt.js'
                'lib/**/*.js'
                'test/**/*.js'
            ]

        jshint:
            options:
                browser: true

    grunt.loadNpmTasks 'grunt-sample'
    grunt.registerTask 'default', 'lint sample'

タスクは grunt.coffee として、いままで grunt.js を置いていたところに置きましょう。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5