小编spa*_*dow的帖子

Grunt - 从命令行传递filename变量

我正在努力理解如何从grunt命令行传递部分文件名,以便在特定文件上运行任务(来自已安装的grunt模块).

我希望能够做的是配置一系列任务以从命令行获取filename参数.

我已经尝试在这个页面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');
    });
};
Run Code Online (Sandbox Code Playgroud)

我尝试从命令行运行它,如下所示:

grunt go:app
Run Code Online (Sandbox Code Playgroud)

以js/app.js为目标

我收到此错误:

Aborted due to warnings.
roberts-mbp:150212 - Grunt Tasks robthwaites$ grunt go:app
Loading "Gruntfile.js" tasks...ERROR
>> …
Run Code Online (Sandbox Code Playgroud)

terminal command-line-arguments gruntjs

3
推荐指数
1
解决办法
1177
查看次数

标签 统计

command-line-arguments ×1

gruntjs ×1

terminal ×1