Parameters binding in grunt tasks

坚强是说给别人听的谎言 提交于 2019-12-12 02:56:02

问题


I have problem with grunt tasks:

 watch: {
      jshint: {
        files: ['Gruntfile.js', '<%= version %>/src/**/*.js', '<%= version %>/src/*.js'],
        tasks: ['jshint', 'concat', 'uglify'], 
        options: {
          livereload: true
        }
      }
    }, 

I call it in a function

grunt.registerTask('server', 'A task that runs server', function(version) {
    if (arguments.length === 0) {
      grunt.log.writeln("Please specify Version in arguments (grunt "+this.name+":version)");
    } else {
      grunt.log.writeln(this.name + ", " + version );
      grunt.config.set('version', version);
      grunt.task.run(['jshint', 'concat', 'uglify', 'open', 'connect', 'watch']); 
    }
  });

The problem is the watch task can see version but the tasks in watch don't bind version - here

tasks: ['jshint', 'concat', 'uglify'], 

Outcome:

0.1\src\myjs.js" changed.
\src\new.js cannot write file

回答1:


The solution was to call

watch: {
      jshint: {
        files: ['Gruntfile.js', '<%= version %>/src/**/*.js', '<%= version %>/src/*.js'],
        tasks: ['jshint:<%= version %>', 'concat', 'uglify'], 
        options: {
          livereload: true
        }
      }
    },

with 'jshint:<%= version %>'

Don't know why this happens but it works



来源:https://stackoverflow.com/questions/30255572/parameters-binding-in-grunt-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!