前回のエントリーで監視して、コンパイルして、minifyする方法を書きました。
module.exports = (grunt)-> grunt.initConfig pkg : grunt.file.readJSON 'package.json' watch : coffee_test1: files : "test1/*.coffee" tasks : ["coffee:test1","uglify:test1"] coffee_test2: files : "test2/*.coffee" tasks : "coffee:test2" coffee : test1: files : [ expand : true cwd : "./test1" src : "*.coffee" dest : "./test1/src/" ext : ".js" ] test2: files : [ expand : true cwd : "./test2" src : '*.coffee' dest : "./test2/src/" ext : ".js" ] uglify : test1: files: [ expand: true cwd: "./test1/src" src: "*.js" dest: "./test1/src/" ext: ".min.js" ] test2: files: [ expand: true cwd: "./test2/src" src: "*.js" dest: "./test2/src/" ext: ".min.js" ] grunt.loadNpmTasks 'grunt-contrib-coffee' grunt.loadNpmTasks 'grunt-contrib-watch' grunt.loadNpmTasks 'grunt-contrib-uglify' grunt.registerTask 'default', ['watch'] returnで、これはこれでいいのですが、ディレクトリが追加されるたびに、修正するのがうざい。
一発で解決する方法はないのだろうか?
答えはgrunt-newerでいけそうだ。
npm install grunt-newer --save-devで以下のように書く
module.exports = (grunt)-> grunt.initConfig pkg : grunt.file.readJSON 'package.json' watch : coffee: files : ["./test1/**/*.coffee","./test2/**/*.coffee"] tasks : ["newer:coffee","newer:uglify"] coffee : compile : files : [ expand : true cwd : "./" src : ["**/*.coffee"] dest : "./src" ext : ".js" ] uglify : compress_target: files: [ expand: true cwd : "./src/" src : ["**/*.js"] dest: "./src/" ext: ".min.js" ] grunt.loadNpmTasks 'grunt-newer' grunt.loadNpmTasks 'grunt-contrib-coffee' grunt.loadNpmTasks 'grunt-contrib-watch' grunt.loadNpmTasks 'grunt-contrib-uglify' grunt.registerTask 'default', ['watch'] return実行したら成功しましたー。
参考
Gruntタスクを変更ファイルのみを対象に実行する
0 コメント:
コメントを投稿