如何访问" pkg.version"在grunt-contrib-copy的进程选项中?

时间:2014-03-13 17:52:11

标签: javascript gruntjs grunt-contrib-copy

我的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位上的任务失败。我尝试过很多东西,但似乎都没有。我确定这是一个范围的事情,但我不能为我的生活弄清楚它可能是什么。会喜欢任何帮助!

1 个答案:

答案 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 %>/' }
            ]
        }
    })
}