【发布时间】:2015-03-05 13:11:28
【问题描述】:
我很难理解如何从 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.
谢谢
【问题讨论】:
标签: terminal gruntjs command-line-arguments