2

我的 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。我已经尝试了很多东西,但它们似乎都不起作用。我确定这是一个范围的事情,但我一生都无法弄清楚它可能是什么。希望有任何帮助!

4

1 回答 1

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 %>/' }
            ]
        }
    })
}
于 2014-03-16T18:47:10.613 回答