【问题标题】:How to access "pkg.version" within the process option of grunt-contrib-copy?如何在 grunt-contrib-copy 的进程选项中访问“pkg.version”?
【发布时间】:2014-03-13 17:52:10
【问题描述】:

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

【问题讨论】:

    标签: javascript gruntjs grunt-contrib-copy


    【解决方案1】:

    只需将 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 %>/' }
                ]
            }
        })
    }
    

    【讨论】:

    • 有时最简单的答案是最明显的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 2018-02-13
    • 2015-07-05
    • 1970-01-01
    相关资源
    最近更新 更多