我曾以为在grunt.registerTask(taskName,taskList)中,任务列表会按顺序运行(即一个完成后再进行下一个)。 我猜这不是这种情况?
考虑到这个任务:
grunt.registerTask('local-debug', [
'clean',
'concat:local',
'ngconstant:common',
'targethtml:local',
'copy:debug'
]);
我应该如何确保在运行copy任务之前,concat/ngconstant/targethtml任务已经完成?我遇到了问题,因为ngconstant在concat完成之前就开始运行了。
编辑:任务未按顺序运行的详细信息。
'concat:local'会创建一个aggregate.json文件,该文件由'ngconstant:common'使用。如果我删除现有的aggregate.json文件,则ngconstant:common任务会出错,因为缺少aggregate.json文件(但是文件确实会在ngconstant运行后创建)。此外,如果我不删除文件,只是做一些更改,例如更改concat使用的源文件中的版本号,则ngconstant创建的文件不会捕获更改,因为它不会等待concat创建新的aggregate.json。
编辑2:任务代码
concat: {
options: {
banner: '{"appConfig": {',
footer: "}}",
separator: ','
},
local: {
src: ["app/config/common-config.json", "app/config/local.json"],
dest: "app/config/aggregate-config.json"
}
},
ngconstant: {
options: {
space: ' ',
wrap: '(function(){\n\n"use strict";\n\n {%= __ngModule %}\n\n}());',
name: 'CoreConfig',
dest: 'app/scripts/config.js'
},
common: {
constants: grunt.file.readJSON('app/config/aggregate-config.json')
}
}
local-debug
任务时,它会发生,而不是在任何监视运行之外。 - mrshickadance