我的Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
iisDeploy: {
options: {
process: function (content, srcpath) {
return content.replace("pre-release", "v" + pkg.version);
}
},
files: [
{ expand: true, cwd: 'build/pre-release/', src: '**', dest: '/location/v<%= pkg.version %>/' }
]
}
})
}
pkg.version
位上的任务失败。我尝试过很多东西,但似乎都没有。我确定这是一个范围的事情,但我不能为我的生活弄清楚它可能是什么。会喜欢任何帮助!
答案 0 :(得分:3)
只需将pkg存储在变量中:
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
grunt.initConfig({
pkg: pkg,
copy: {
iisDeploy: {
options: {
process: function (content, srcpath) {
return content.replace("pre-release", "v" + pkg.version);
}
},
files: [
{ expand: true, cwd: 'build/pre-release/', src: '**', dest: '/location/v<%= pkg.version %>/' }
]
}
})
}