Javascript Grunt.js中的变量
是否可以在grunt.js中访问通配符之外的通配符变量? 例如,我的配置如下所示:Javascript Grunt.js中的变量,javascript,gruntjs,wildcard,Javascript,Gruntjs,Wildcard,是否可以在grunt.js中访问通配符之外的通配符变量? 例如,我的配置如下所示: module.exports = function(grunt) { grunt.initConfig({ globalConfig: grunt.file.readJSON('src/config.json'), pkg: grunt.file.readJSON('package.json'), concat: { options: { separator: ';' }, dist: {
module.exports = function(grunt) {
grunt.initConfig({
globalConfig: grunt.file.readJSON('src/config.json'),
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';'
},
dist: {
src: ['src/**/*.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
}
}
},
qunit: {
files: ['test/**/*.html']
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint', 'qunit']
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);
};
{
"buildOrder": ["file1.js", "file2.js", "file3.js"]
}
<%= globalConfig.buildOrder %>
例如,如何访问buildOrder数组并在concat.dist.src中使用它
通过通配符,我可以这样访问:
module.exports = function(grunt) {
grunt.initConfig({
globalConfig: grunt.file.readJSON('src/config.json'),
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';'
},
dist: {
src: ['src/**/*.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
}
}
},
qunit: {
files: ['test/**/*.html']
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint', 'qunit']
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);
};
{
"buildOrder": ["file1.js", "file2.js", "file3.js"]
}
<%= globalConfig.buildOrder %>
然后不起作用?我尝试了src:但我只得到警告:警告:必须提供模式Use-force才能继续。我认为它不起作用,因为globalConfig.buildOrder是一个数组。