admin管理员组文章数量:1187320
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
{
"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; e.g. <%= pkg.lint[0] %>. Thanks in advance for your help!
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
{
"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; e.g. <%= pkg.lint[0] %>. Thanks in advance for your help!
Share Improve this question edited Sep 13, 2012 at 20:40 Phillip Whisenhunt asked Sep 13, 2012 at 14:25 Phillip WhisenhuntPhillip Whisenhunt 1,3052 gold badges18 silver badges30 bronze badges 6 | Show 1 more comment3 Answers
Reset to default 25Since gruntjs in run in node you can access the package.json like:
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.
Try this instead:
lint: {
files: '<config:pkg.lint>'
}
I found this syntax in Grunt's jQuery init task.
grunt.initConfig({
lint: grunt.file.readJSON('package.json').lint,
});
本文标签: javascriptHow to pass in packagejson array to gruntjsStack Overflow
版权声明:本文标题:javascript - How to pass in package.json array to grunt.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738344098a2077731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<%= pkg.lint %>
instead? The lint task seems to accept an array, not a comma-separated list of files... – Dmitry Pashkevich Commented Sep 13, 2012 at 17:03grunt.registerTask('default', 'lint', function() {console.log(grunt.config('lint'))});
and see what gets output in the console... – Dmitry Pashkevich Commented Sep 13, 2012 at 19:19