Gruntjs 带有调试和发布目标的grunt contrib watch
例如,使用Gruntjs 带有调试和发布目标的grunt contrib watch,gruntjs,Gruntjs,例如,使用concat插件,我们可以在Gruntfile.js中设置调试和发布目标: grunt.initConfig({ concat: { debug: { }, release: { }, } 插件可以有多种配置吗 执行此操作时: watch: { debug: { options: { livereload: true, nospawn: true }, copy: { files:
concat
插件,我们可以在Gruntfile.js中设置调试和发布目标:
grunt.initConfig({
concat: {
debug: {
},
release: {
},
}
插件可以有多种配置吗
执行此操作时:
watch: {
debug: {
options: {
livereload: true,
nospawn: true
},
copy: {
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy']
}
我收到一个错误,提示“验证配置中是否存在属性watch.debug.files”
这也不起作用:
watch: {
debug: {
options: {
livereload: true,
nospawn: true
},
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy'],
files: ['jade/**/*.jade'],
tasks: ['jade:devmock']
…因为我不能有两个文件
-数组或两个任务
-数组。(它忽略除第一对文件/任务以外的所有文件/任务)
是否有其他方法可以实现我的目标?是的
配置更为平坦
watch: {
debug: {
files: ['js/app/**/*.js', 'js-amd/**/*.js'],
tasks: ['copy'],
options: {
livereload: true,
nospawn: true
}
}
}
您将在此处找到更多示例:如果您需要两组文件,则需要一组新的配置文件
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
}
}
}
我使用的一种解决方案是定义多个监视目标并重命名监视任务,如下所示:
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']);
对不起,我已经试过了。如果您只有一组文件和一组任务,它就可以工作。请参阅编辑的问题,了解如果您有更多信息,会发生什么情况我得到了一个新的答案,这就是您想要做的吗?