grailsでcoffee-scriptを使う

https://github.com/edvinasbartkus/grails-coffeescript-resources
で簡単に出来た。

とりあえず入れる。

grails install-plugin coffeescript-resources

後はresource pluginと同じように使える。ApplicationResources.groovyにcoffeeのモジュールを追加してみる。

modules = {
    application {
        resource url:'js/application.js'
    }

    coffee {
        dependsOn 'jquery'
        resource url:'cs/Hello.coffee'
    }
}

もうほんとresource pluginと同じように使えるのでgspで、

<r:require modules="coffee"/>

とかしてやればいい。

あとは勝手に.coffeeファイルはコンパイルしてjsにしたものを勝手にリンクしてくれるみたい。便利。

cs/Hello.coffeeはこんなん。jqueryとかも普通に使える。

jQuery -> 
    for number in [0...5]
        $('#output').append('<p>hello coffee</p>')