0

Folder Structure

Please refer below two images for folder structure.

https://i.stack.imgur.com/5aEzi.png | https://i.stack.imgur.com/Hsapz.png

How can we write a task in root gulfile.js (without creating gulpfile.js for each and individual folder) to minify CSS and JS for this kind of file structure? In addition, it should store the minified version of the file into that respective folder only. For example, if I am making changes in page3 CSS and JS file, it should store the minified CSS in /page3/css/page3.min.css and the same way it should store the minified JS in /page3/js/page3.min.js.

Same way, I am just wondering if it is possible to set the watch so for example if you are making changes in page2 CSS and JS, it detects that and after saving file it stores the minified version in their respective folder only.

I am still learning gulp and trying to figure this out but I am not able to.

Going forward, folder structure may go one level deep. Like page3 has its sub page and that subpage has it's own CSS and JS folder. it would be great if that could be covered as part of this answer as well.

Any help would be appreciative.

Thanks in an advance.

  • Look at the section "options.base" in the gulp documentation for more explanation on how to set filepaths in a gulp script: https://github.com/gulpjs/gulp/blob/master/docs/API.md – Our_Benefactors Jul 31 '17 at 21:03
  • Thank you very much! That helped! Now after setting the src with globs the problem I am facing with "watch" is that even if I just update one file, it goes and minify all the files which match the globs. I was just wondering if there is a way to setup task or watch to only minify the file that has been updated – user1684181 Jul 31 '17 at 23:47
  • There a number of plugins that will do what you want. See https://www.npmjs.com/package/gulp-newer for example. – Mark Aug 01 '17 at 02:04
  • "gulp-newer" seems not to be working as source and destination folder/file is same. I have tried "gulp-changed" too. I am still looking for work around. – user1684181 Aug 01 '17 at 15:20

0 Answers0