我刚刚开始使用Grunt,并希望每次修改文件时使用[GitHub页面]运行grunt-contrib-watch
[GitHub页面] lint我的JavaScript(使用grunt-contrib-jshint
[GitHub页面])并运行grunt-nodemon
[GitHub页面],同时使用grunt-concurrent
[GitHub页面].
据我所知(我显然没有)我的Gruntfile应该:
concurrent
默认运行
concurrent
运行 watch
watch
jshint
每次修改文件时都会运行
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ concurrent: { dev: [ 'watch' ], options: { logConcurrentOutput: true } }, jshint: { server: [ '**/*.js', '!node_modules/**/*.js' ], options: { node: true } }, watch: { all: [ '**/*/.js', '!node_modules/**/*.js' ], tasks: [ 'jshint' ] } }); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', [ 'concurrent:dev'/*, 'jshint', 'watch'*/ ]); }; grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', [ 'concurrent:dev' ]); };
NB我还没有添加grunt-nodemon
到混音中.
它看起来像是concurrent
在运行,watch
但是当我修改文件时,它似乎jshint
没有运行.我当然不会在终端中获得任何输出(我认为logConcurrentOutput: true
这样做).
这是我在终端中获得的输出:
Running "concurrent:dev" (concurrent) task Running "watch" task Waiting... Done, without errors.
我还想jshint
在我第一次运行default
任务时运行(以及修改文件时).
任何人都可以了解我的错误吗?
谢谢!
watch
如果没有找到"观察"的文件,该任务将退出; 按照这个问题.
为了轻松告诉watch
观看与jshint
任务相同的文件,我使用Grunt的模板引擎来引用与任务相同Array
的文件jshint
.
然后我添加jshint
到要运行的并发任务列表中,这样它最初会运行并且当我修改文件时(带watch
).
这是我的工作Gruntfile
:
module.exports = function (grunt) { grunt.initConfig({ concurrent: { dev: [ 'jshint', 'watch' ], options: { logConcurrentOutput: true } }, jshint: { server: [ '**/*.js', '!node_modules/**/*.js' ], options: { node: true } }, watch: { files: '<%= jshint.server %>', tasks: [ 'jshint' ] } }); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', [ 'concurrent' ]); };