例如,使用concat插件,我们可以在Gruntfile.js中设置调试和发布目标:
grunt.initConfig({
concat: {
debug: {
},
release: {
},
}grunt-contrib-watch插件可以有多种配置吗?
执行此操作时:
watch: {
debug: {
options: {
livereload: true,
nospawn: true
},
copy: {
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy']
}我收到一个错误,显示为verifying property watch.debug.files exists in config。
这也不起作用:
watch: {
debug: {
options: {
livereload: true,
nospawn: true
},
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy'],
files: ['jade/**/*.jade'],
tasks: ['jade:devmock']...since I不能有两个files-arrays或两个tasks-arrays。(它将忽略除第一个files/tasks-pair之外的所有-pair)
有没有其他方法可以达到我想要的效果?
发布于 2013-06-25 17:42:45
是。
配置稍微扁平化一点。
watch: {
debug: {
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy'],
options: {
livereload: true,
nospawn: true
}
}
}你可以在这里找到更多的例子:https://github.com/gruntjs/grunt-contrib-watch
发布于 2013-06-25 18:55:41
如果需要两组文件,则需要一组新的配置
watch: {
debug: {
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy'],
options: {
livereload: true,
nospawn: true
}
},
other-debug: {
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy'],
options: {
livereload: true,
nospawn: true
}
}
}发布于 2014-02-13 11:32:02
我使用的一个解决方案是定义多个监视目标,并将监视任务重命名为:
watch: {
scripts: {
files: ['js/**/*.js'],
tasks: ['concat', 'uglify'],
options: {
spawn: false
}
}
},
// Don't uglify in dev task
watchdev: {
scripts: {
files: ['js/**/*.js'],
tasks: ['concat'],
options: {
spawn: false
}
}
}
grunt.loadNpmTasks('grunt-contrib-watch');
// Rename watch to watchdev and load it again
grunt.renameTask('watch', 'watchdev');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
grunt.registerTask('dev', ['watchdev']);https://stackoverflow.com/questions/17293869
复制相似问题