大佬教程收集整理的这篇文章主要介绍了node.js – Grunt watch:只编译一个文件而不是全部,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
coffee: { dynamic_mappings: { files: [{ expand: true,cwd: 'assets/scripts/src/',src: '**/*.coffee',dest: 'assets/scripts/dest/',ext: '.js' }] } }
我想要做的是使用watch来编译任何已更改的咖啡文件并仍然保持文件夹结构.这对于此监视任务使用上述任务:
watch: { coffeescript: { files: 'assets/scripts/src/**/*.coffee',tasks: ['coffee:dynamic_mappings'] } }
问题是,当一个文件发生变化时,它会将整个咖啡目录再次编译成Javascript,如果它只编译变成Javascript的单个咖啡文件就会很棒.这在Grunt中是否自然可行,或者这是一个自定义功能.这里的关键是它必须保持文件夹结构,否则它会很容易.
此示例是grunt-contrib-watch readme中示例的略微修改版本.
希望能帮助到你!
var path = require("path"); var srcDir = 'assets/scripts/src/'; var destDir = 'assets/scripts/dest/'; module.exports = function( grunt ) { grunt.initConfig( { coffee: { dynamic_mappings: { files: [{ expand: true,cwd: srcDir,dest: destDir,ext: '.js' }] } },watch : { coffeescript : { files: 'assets/scripts/src/**/*.coffee',tasks: "coffee:dynamic_mappings",options: { spawn: false,//important so that the task runs in the same context } } } } ); grunt.event.on('watch',function(action,filepath,target) { var coffeeConfig = grunt.config( "coffee" ); // update the files.src to be the path to the modified file (relative to srcDir). coffeeConfig.dynamic_mappings.files[0].src = path.relative(srcDir,filepath); grunt.config("coffee",coffeeConfig); } ); grunt.loadNpmTasks("grunt-contrib-coffee"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.registerTask("default",[ "coffee:dynamic_mappings","watch:coffeescript"]); };
以上是大佬教程为你收集整理的node.js – Grunt watch:只编译一个文件而不是全部全部内容,希望文章能够帮你解决node.js – Grunt watch:只编译一个文件而不是全部所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。