Grunt.js dependency management

Is there a way to specify file dependencies in Grunt? That is, if I have:

global/page.jade project/index.jade -- includes global/page.jade project/about.jade -- includes global/page.jade project/test.jade 

and I modify global/page.jade , then I would like to recompile project/index|about.jade . I checked the plugins, but could not find anything that would provide this functionality.

+4
source share
2 answers

grunt watch use in your gruntfile.js file as follows

 ... watch: { scripts: { files: 'src/**/*', tasks: ['buildDevelopment'], options: { interrupt: true, }, } grunt.registerTask('buildDevelopment', ['clean' ,'jade' ,'copy:development' ,'bowercopy:development' ]); ... 
+5
source

I would suggest improving the Atillas solution. Restoring all templates with each change is not optimal, and you will be disappointed in large projects.

Here is what should help:


Use the new plugin to process only modified files

Install: npm install grunt-newer --save-dev
Docs: https://www.npmjs.org/package/grunt-newer#optionsoverride
Using

  • prefix tasks with new:
  • add grunt.loadNpmTasks ('grunt-newer); to gruntfile
  • use the override option to check (the magic you are looking for)

newer: { options: { override: function (detail, include) { if (detail.task === 'jade') { checkForModifiedImports(detail.path, detail.time, include); } else { include(false); } } } }



Using the clock to detect file changes

Install: npm install grunt-contrib-watch --save-dev Docs: https://www.npmjs.org/package/grunt-contrib-watch
Application:

  • add grunt.loadNpmTasks ('grunt-contrib-watch'); to gruntfile
  • the task might look something like this.

watch: { scripts: { files: '**/*.jade', tasks: ['newer:jade'], options: { interrupt: true }, }, }

+2
source

All Articles