我在 grunt-ng-constant
中遇到了一个奇怪的问题,其中 3 个目标中只有 2 个有效。
我的配置如下所示:
grunt.initConfig({
ngconstant: {
options: {
space: ' ',
wrap: '"use strict";\n\n {%= __ngModule %}',
name: 'config'
},
// Environment targets
development: {
options: {
dest: '<%= yeoman.app %>/scripts/config.js',
},
constants: {
ENV: {
name: 'development',
apiEndpoint: 'http://your-development.api.endpoint:3000'
}
}
},
staging: {
options: {
dest: '<%= yeoman.app %>/scripts/config.js',
},
constants: {
ENV: {
name: 'staging',
apiEndpoint: 'http://your-staging.api.endpoint:3000'
}
}
},
production: {
options: {
dest: '<%= yeoman.dist %>/scripts/config.js',
},
constants: {
ENV: {
name: 'production',
apiEndpoint: 'http://api.livesite.com'
}
}
}
}
})
我有以下任务正在注册
grunt.registerTask('development', [
'ngconstant:development'
]);
grunt.registerTask('staging', [
'ngconstant:staging'
]);
grunt.registerTask('production', [
'ngconstant:production'
]);
如果我运行以下两个命令,一切正常,并且生成了 config.js
文件,看起来很棒。
grunt development
grunt staging
但是运行 grunt production
不会生成 config.js
文件。我似乎无法弄清楚为什么会这样。
最佳答案
我同时开发和暂存您正在生成的任务 config.js
以 <%= yeoman.app %>
开头的路径中的文件,但在生产中,您使用的是以 <%= yeoman.dist %>
开头的.
我会检查第二条路径(或 yeoman.dist
)是否存在。
关于javascript - grunt-ng-constant 目标不能持续工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32449629/