0

I use Gulp JS in my themes but the issue I'm having is we work on many themes in our drupal site (sometimes up to 40!).

I want to avoid repeating the same "node_modules", "gulpfile.js" and "package.json" files in every single theme. If we want to change 1 of those files, we would have to update each file in every theme across all sites which is going to get too messy.

I would like to have the Gulp files live in sites/all/libraries and have gulp watch my theme that I'm working on.

To anyone experienced with Gulp, any idea's on how this can work?

Edit:

  1. I have moved the 2 gulp files & node_modules folder into /sites/all/libraries/gulp
  2. I have edited gulp.js to point to the theme I'm working on, code is below (I have tried a few different combinations including an absolute path):

gulp.task('less', function() { gulp.src('../themes/theme_name/css/style.less')

When I type gulp in the command line in my theme directory I get this error:

Local gulp not found in /var/www/site_name/sites/all/themes/theme_name

If I go into sites/all/libraries/gulp, type gulp in the command line, the gulp process starts, but if I edit a Less file and save it, gulp doesn't compile the css.

Thank You

  • It's pretty simple, you just point the current working directory for individual tasks to whatever's relevant for the theme you're working on. Could you edit the question and provide details of exactly where you're stuck? And don't forget that the point of Gulp/Grunt is that they're project-centric - the second you need one tiny bit of functionality different for one individual theme, the whole system breaks down – Clive Jan 19 '15 at 10:50
  • Thanks for your reply Clive. I thought it would be that simple too until I got the error as I explained in my edit. – Rick Bergmann Jan 19 '15 at 13:55
  • Have you tried setting gulp.cwd(...) to /var/www/site_name/sites/all/themes? I use grunt myself but I'm guessing (hoping) gulp has the same philosophy – Clive Jan 19 '15 at 16:35
  • I have now and still no luck unfortunately, although I think it's getting close now as CWD is included in gulp. I found in gulp docs when setting the cwd they are going down from a root path, where I'm going up from libraries and then down into themes (I don't see how that would be a problem). I also tried the absolute path. I will keep fiddling and post the solution if I figure it out! Ref: github.com/gulpjs/gulp/blob/master/docs/recipes/… – Rick Bergmann Jan 20 '15 at 14:15
1

I have finally found the best solution for this so I'm posting it incase anyone has a similar issue:

  1. Add gulp (package.json, gulpfile.js & node_modules) to a centralized location (eg: sites/all/libraries/gulp)

  2. In the root of each theme, create 3 symbolic links that point to gulpfile.js, package.json and node_modules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.