如何将package.json数组传递给grunt.js

问题描述:

有没有办法将一个数组传递给package.json文件中的grunt.js?我尝试了几种不同的方式,但他们都没有效果。我目前有:

is there a way to pass in an array to grunt.js from the package.json file? I've tried a few different ways and none of them seem to work. I currently have:

/*global module:false*/
module.exports = function(grunt) {

     // Project configuration.
     grunt.initConfig({
    pkg: '<json:package.json>',

    lint: {
      files: '<%= pkg.lint.join(", ") %>'
    }

    // Default task 'lint qunit concat min'
    grunt.registerTask('default', 'lint');
};

package.json

package.json

{
  "lint": [   
              "grunt.js",
              "test.js"
          ]
}

我唯一能找到的解决方案是传递一个特定的索引这个数组;例如<%= pkg.lint [0]%>。
在此先感谢您的帮助!

The only solution that I have been able to find is to pass in a specific index of the array; e.g. <%= pkg.lint[0] %>. Thanks in advance for your help!

因为gruntjs在节​​点中运行,所以你可以像访问package.json一样:

Since gruntjs in run in node you can access the package.json like:

var package = require('./package.json'),
    property = package.property[0];