Answer the question
In order to leave comments, you need to log in
Move the compilation of Pug to Gulp one level up, relative to the target folder - is it possible?
Have a nice day, everyone!
Interested in the opinion of experienced minds in Gulp - is it possible to transfer the compilation of html from Pug to a folder a level higher, relative to the .pug file. This changes the name of the folder.
Situation for which it was needed:
I make websites for the cities of the Moscow region, exclusively on Pug. There are 16 sites in total on the same layout, only part of the content stored in variables changes.
Thus, each city has its own folder in which html should appear. In the same folder is the pug folder, which contains the final files for compilation.
That. structure of the whole idea:
C/WebServer/domains/beton-Iventeevka.ru/pug/
C/WebServer/domains/beton-Reutov.ru/pug/
C/WebServer/domains/#{Name-Sity.ru}/pug/
Such 16 pieces.
#{Name-Sity.ru} - city-specific folder
/pug/ - folder of final files.
The goal is to avoid creating a Galp build for each individual folder, but to compile all cities with 1 command.
Those. at the /domains/ folder level, a Galp assembly is created, a universal path is written in it via /**/ or something else, and something is written in dest relative to the final position of the file + going up a level.
I've tried similar attempts:
gulp.task('pug', function(){
return gulp.src('../domains/**/gulp/pug/*.pug', {base: './'})
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('../'))
});
I tried to return through the return file.base function - it turned out to put everything in the same folder, but it didn’t work one level up.
If you try to summarize, then the essence of the problem is precisely in dest - how to raise a level / an arbitrary number of levels, relative to the final file
Answer the question
In order to leave comments, you need to log in
Here is the recipe (if I understood the question correctly):
const path = require('path');
const gulp = require('gulp');
const pug = require('gulp-pug');
const cities = [
{
cityName : 'city1',
},
{
cityName : 'city2',
}
];
gulp.task('views', function(done) {
cities.forEach(function(city, index, cities) {
gulp.src('template/city.pug')
.pipe(pug({
data : city
}))
.pipe(gulp.dest(path.join('..', '..', 'domains', city.cityName)));
});
done();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question