Gruntjs Grunt:将源文件数组发送到Grunt任务uglify
我似乎在文档中找不到答案。我想将一组源文件从my package.json发送到grunt任务 这是我的config.jsonGruntjs Grunt:将源文件数组发送到Grunt任务uglify,gruntjs,grunt-contrib-uglify,Gruntjs,Grunt Contrib Uglify,我似乎在文档中找不到答案。我想将一组源文件从my package.json发送到grunt任务 这是我的config.json { "sourceFiles": ["src/js/d3js/d3.js", "src/js/testingGrunt.js"] } 这是我的Grunfile.js module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt
{
"sourceFiles": ["src/js/d3js/d3.js", "src/js/testingGrunt.js"]
}
这是我的Grunfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: grunt.file.readJSON('config.json')
});
// Load the plugin that provides the concat tasks.
grunt.loadNpmTasks('grunt-contrib-concat');
// defining my concat task
grunt.config('concat', {
dist: {
//src: ['src/js/testingGrunt.js', 'src/js/d3js/d3.js'],
src: '<%config.sourceFiles%>',
dest: 'build/<%= pkg.name %>-build.js'
}
});
// Load the plugin that provides the uglify tasks.
grunt.loadNpmTasks('grunt-contrib-uglify');
// defining my uglify task
grunt.config('uglify', {
options: {
banner: '/*\n* ©<%= pkg.author%>\n* <%= pkg.name %>\n* <%= grunt.template.today("yyyy-mm-dd HH:mm:ss") %> \n*/\n'
},
build: {
src: 'build/<%= pkg.name %>-build.js',
dest: 'build/<%= pkg.name %>-build.min.js'
}
});
// Default task(s).
var defaultTasks;
defaultTasks = ['concat', 'uglify']
grunt.registerTask('default', defaultTasks);
};
module.exports=函数(grunt){
//项目配置。
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
config:grunt.file.readJSON('config.json')
});
//加载提供concat任务的插件。
grunt.loadNpmTasks(“grunt-contrib-concat”);
//定义我的concat任务
grunt.config('concat'{
地区:{
//src:['src/js/testingGrunt.js','src/js/d3js/d3.js'],
src:“”,
dest:'build/-build.js'
}
});
//加载提供丑陋任务的插件。
grunt.loadNpmTasks(“grunt-contrib-uglify”);
//定义我丑陋的任务
grunt.config('uglify'{
选项:{
横幅:'/*\n*)\n*\n*\n*/\n'
},
建造:{
src:'build/-build.js',
dest:'build/-build.min.js'
}
});
//默认任务。
虚拟现实任务;
defaultTasks=['concat','uglify']
registerTask('default',defaultTasks);
};
grunt.config中注释掉的行('concat',…工作得很好。但是我想设置gruntfile以从配置文件读取文件
最后,我将在这个grunt任务中做其他事情,我想设置它,这样我就不需要编辑grunt文件。看起来模板语法已关闭,请尝试替换:
src: '<%config.sourceFiles%>',
src:“”,
以下是:
src: '<%= config.sourceFiles %>',
src:“”,
我更新了问题。我正试图从config.json将文件放入grunt任务中更新答案。干杯!:)