Answer the question
In order to leave comments, you need to log in
How to make a path alias for Gulp?
Hello! I want to track twig files through gulp so that when the file changes, the page is automatically updated.
In twig, files are inherited through such an entry
{% extends '@VendorBundle/base_layout.html.twig' %}
because of this, errors in the gallop fly out, he does not understand what kind of path this is. @VendorBundle
, it substitutes the path that I will indicate to it, for example vendor/bundle/base.html.twig
? /*global require*/
"use strict";
var gulp = require('gulp'),
twig = require('gulp-twig'),
plumber = require('gulp-plumber'),
browserSync = require('browser-sync'),
replace = require('gulp-replace');
/*
* Directories here
*/
var paths = {
build: './public/build/',
};
gulp.task('twig', function () {
return gulp.src(['templates/*.twig'])
.pipe(replace('@VendorBundle', 'vendor/vendor-bundle/Resources/views/'))
// Stay live and reload on error
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(twig())
.on('error', function (err) {
process.stderr.write(err.message + '\n');
this.emit('end');
})
.pipe(gulp.dest(paths.build));
});
gulp.task('rebuild', ['twig'], function () {
// BrowserSync Reload
browserSync.reload();
});
gulp.task('browser-sync', ['twig'], function () {
browserSync({
server: {
baseDir: paths.build
},
notify: false,
});
});
gulp.task('watch', function () {
gulp.watch([
'templates/**/*.twig',
],
{cwd:'./'},
['rebuild']);
});
gulp.task('build', ['twig']);
gulp.task('default', ['browser-sync', 'watch']);
Unable to find template file /home/user/PhpstormProjects/application/templates/@VendorBundle/layout.html.twig. Error: ENOENT: no such file or directory, stat '/home/user/PhpstormProjects/application/templates/@VendorBundle/layout.html.twig'
Answer the question
In order to leave comments, you need to log in
@VendorBundle is the namespace https://github.com/twigjs/twig.js/wiki#user-conten...
There is a corresponding option in gulp-twig https://github.com/zimmen/gulp-twig/blob/ 56f060de3...
.pipe(twig({
namespaces: {
'VendorBundle': 'vendor/vendor-bundle/Resources/views/'
}
}))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question