Hi,

Since I use block rewrites so frequently in my front-end development, I though it would be nice to add twig saves to the gulp routine.
Here's what I did :

In your config.json, add this code just before "images"

  "twig": {
    "src": [
      "templates/**/*.twig"
    ]
  },

in gulpfile.js

Add this just over where it says // Compress images.

// Twig.
gulp.task('twig', function() {
  return gulp.src(config.twig.src)
    .pipe(browserSync.reload({ stream: true }));
});

then watch it by adding a line in the // Watch task. like so :

// Watch task.
gulp.task('watch', function() {
  gulp.watch(config.css.src, ['css']);
  gulp.watch(config.images.src, ['images']);
  gulp.watch(config.twig.src, ['twig']);
});

There you go. Now saving twigs inside template folder will refresh your browser!
Note: Of course, it will only works if your drupal settings remove twig cache ;)

Comments

JFKiwad created an issue.

PI_Ron’s picture

Thanks a lot for this, great tip. @JFKiwad

shadcn’s picture

Thanks for sharing @JFKiwad. I'm using it on my local setup :)

fcasanellas’s picture

Very useful! Thanks!

doxigo’s picture

And the medal of badass tweaks goes to @JFKiwad

Dinesh18’s picture

Looks great. Thanks @JFKiwad