我很难理解如何从grunt命令行传递部分文件名,以便在特定文件上运行任务(来自已安装的grunt模块)。
我想要做的是配置一系列任务,以从命令行获取文件名参数。
我尝试重新制作了这个页面http://chrisawren.com/posts/Advanced-Grunt-tooling上的最终示例,但我有点盲目。希望有人能快速回答。
这是我的Gruntfile:
module.exports = function (grunt) {
grunt.initConfig({
globalConfig: globalConfig,
uglify: {
js: {
options: {
mangle: true
},
files: {
'js/<%= globalConfig.file %>.min.js': ['js/<%= globalConfig.file %>.js']
}
}
},
});
// Load tasks so we can use them
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('go', 'Runs a task on a specified file', function (fileName){
globalConfig.file = fileName;
grunt.task.run('uglify:js');
});
};
我尝试像这样从命令行运行它:
grunt go:app
目标为js/app.js
我收到了这个错误:
Aborted due to warnings.
roberts-mbp:150212 - Grunt Tasks robthwaites$ grunt go:app
Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: globalConfig is not defined
Warning: Task "go:app" not found. Use --force to continue.
谢谢