Grunt usemin with patterns

Given the following directory structure:

– Gruntfile.js – app |– index.php |– js |– css |– templates |– template.php – dist 

How to configure grunt usemin to update the links to styles and scripts in the template file relative to index.php that uses the template?

Currently, the tasks are as follows:

 useminPrepare: { html: '<%= yeoman.app %>/templates/template.php', options: { dest: '<%= yeoman.dist %>' } }, usemin: { html: ['<%= yeoman.dist %>/{,*/}*.php'], css: ['<%= yeoman.dist %>/css/*.css'], options: { dirs: ['<%= yeoman.dist %>'] } } 

And the blocks inside the template look like this:

 <!-- build:js js/main.js --> <script src="js/script1.js"></script> <script src="js/script2.js"></script> <!-- endbuild --> 
+7
source share
1 answer

Ok, I realized: The solution is to use an alternative search path:

 <!-- build:<type>(alternate search path) <path> --> ... HTML Markup, list of script / link tags. <!-- endbuild --> 

Assembly blocks now look like this:

 <!-- build:js(app) js/main.js --> <script src="js/script1.js"></script> <script src="js/script2.js"></script> <!-- endbuild --> 

and the usemin task is configured as follows:

 usemin: { html: '<%= yeoman.dist %>/templates/template.php', css: ['<%= yeoman.dist %>/css/*.css'], options: { dirs: ['<%= yeoman.dist %>'] } } 
+4
source

All Articles