Search subtask monitoring

I have the following Gruntfile.coffee. I am tracking the viewer task as shown below to see the file changes and then compile the modified file into a coffee script.

# Watch task watch: coffee: files: ['client/**/*.coffee','server/**/*/.coffee'] options: nospawn: true livereload: true # Watch changed files grunt.event.on 'watch', (action, filepath) -> cwd = 'client/' filepath = filepath.replace(cwd,'') grunt.config.set('coffee', changed: expand: true cwd: cwd src: filepath dest: 'client-dist/' ext: '.js' ) grunt.task.run('coffee:changed') 

However, I would like to add another task to view files that are not coffee files. How will I track these changes?

I was thinking about doing

 # Watch copy task grunt.event.on 'watch:copy', (action,filepath) -> ... # Watch coffee task grunt.event.on 'watch:coffee', (action,filepath) -> ... 

but this does not seem to work. Ideas?

+4
source share
2 answers

My decision is doing its job, but not really. I welcome the best answers

Basically, I map the path of the input file
if him. coffee launches the coffee compilation task
if him. * start copy task

 # Watch changed files grunt.event.on 'watch', (action, filepath) -> # Determine server or client folder path = if filepath.indexOf('client') isnt -1 then 'client' else 'server' cwd = "#{path}/" filepath = filepath.replace(cwd,'') # Minimatch for coffee files if minimatch filepath, '**/*.coffee' # Compile changed file grunt.config.set('coffee', changed: expand: true cwd: cwd src: filepath dest: "#{path}-dist/" ext: '.js' ) grunt.task.run('coffee:changed') # Minimatch for all others if minimatch filepath, '**/*.!(coffee)' # Copy changed file grunt.config.set('copy', changed: files: [ expand: true cwd: cwd src: filepath dest: "#{path}-dist/" ] ) grunt.task.run("copy:changed") 
+2
source

Take a look at the note at the bottom of the watch case example: https://github.com/gruntjs/grunt-contrib-watch#using-the-watch-event

The watch event is not intended to replace the Grunt API. Use tasks instead:

 watch: options: nospawn: true livereload: true coffee: files: ['client/**/*.coffee','server/**/*/.coffee'] tasks: ['coffee'] copy: files: ['copyfiles/*'] tasks: ['copy'] 
+1
source

Source: https://habr.com/ru/post/1480393/


All Articles