问题
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