[英]How to pass in package.json array to grunt.js
is there a way to pass in an array to grunt.js from the package.json file? 有没有办法从package.json文件传入数组到grunt.js? 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"
]
}
The only solution that I have been able to find is to pass in a specific index of the array; 我能找到的唯一解决方案是传入数组的特定索引; eg <%= pkg.lint[0] %>.
例如<%= pkg.lint [0]%>。 Thanks in advance for your help!
在此先感谢您的帮助!
Since gruntjs in run in node you can access the package.json like: 由于gruntjs在节点中运行,你可以访问package.json,如:
var package = require('./package.json'),
property = package.property[0];
I think that the <%= … %>
syntax (variable interpolation in Underscore's template system ) can only output strings, not arrays/objects. 我认为
<%= … %>
语法( Underscore模板系统中的变量插值)只能输出字符串,而不能输出数组/对象。
Try this instead: 试试这个:
lint: {
files: '<config:pkg.lint>'
}
I found this syntax in Grunt's jQuery init task . 我在Grunt的jQuery init任务中找到了这种语法。
grunt.initConfig({ lint: grunt.file.readJSON('package.json').lint, });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.