Answer the question
In order to leave comments, you need to log in
Building a gulp project, how to make wiredep and userref friends if .html files are in different folders?
When building the project, there were difficulties, there is such a file structure:
I use the Jade preprocess, when compiling html files, wiredep automatically prescribes the paths to the bower libraries, everything works until you try to build the project. Due to the fact that the .jade files are in different folders, files are created in html during compilation while maintaining the folder structure. Paths to bower components are written in files, but since some files are in separate folders, relative paths are set for them. And when you try to build, userref swears on the path to the files of those files that are in folders and have relative paths.
Assembly
gulp.task('build',['clean'], function () {
return gulp.src('src/*.html')
.pipe(useref({searchPath: './src/'}))
.pipe(gulpif('*.js', uglify()))
.pipe(gulpif('*.css', minifyCss()))
.pipe(gulp.dest('dist'));
});
/*-------------clean--------*/
gulp.task('clean', function () {
return gulp.src('dist', {read: false})
.pipe(clean());
});
gulp.task('pug', function buildHTML() {
return gulp.src(['./src/jade/**/*.pug','!./src/jade/**/_*.pug'])
.pipe(pug({
pretty: true
}).on('error', pugErrorHandler))
.pipe(wiredep({
directory : "src/bower/",
ignorePath: '../',
}))
.pipe(gulp.dest('src'))
});
<link rel="stylesheet" href="bower/select2/dist/css/select2.min.css" />
<link rel="stylesheet" href="../bower/select2/dist/css/select2.min.css" />
Answer the question
In order to leave comments, you need to log in
Thanks for the advice. I found a solution that may be useful to you or someone:
wiredep, you can specify several parameters
.pipe(wiredep({
directory : "src/bower/", // Путь к вашим бовер компонентам
ignorePath: '../', // Игнорирует указанный путь
}))
.pipe(useref({
searchPath: './src/', //Ищет данную папку
transformPath: function(filePath) {
return filePath.replace('../','/') // Меняет путь на который указан вторым параметром
}
}))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question