Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #2
PI_Ron CreditAttribution: PI_Ron commentedThanks a lot for this, great tip. @JFKiwad
Comment #3
shadcn CreditAttribution: shadcn at Chapter Three commentedThanks for sharing @JFKiwad. I'm using it on my local setup :)
Comment #4
fcasanellas CreditAttribution: fcasanellas commentedVery useful! Thanks!
Comment #5
doxigo CreditAttribution: doxigo commentedAnd the medal of badass tweaks goes to @JFKiwad
Comment #6
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedLooks great. Thanks @JFKiwad