Answer the question
In order to leave comments, you need to log in
Problem with paths when building front (Gulp.js): how to solve?
The structure is like this:
static
├── build
│ ├── css
│ ├── fonts
│ ├── img
│ └── js
└── src
├── blocks
├── fonts
└── img
var path = {
build: {
js: 'static/build/js',
css: 'static/build/css',
fonts: 'static/build/fonts',
img: 'static/build/img'
},
src: {
vendor_fonts: ['bower_components/**/*.{svg,woff,eot,ttf}', 'semantic/**/*.{svg,woff,eot,ttf}'],
vendor_img: ['bower_components/**/*.{png,jpg,jpeg,gif}', 'semantic/**/*.{png,jpg,jpeg,gif}']
}
};
gulp.task('vendor:img', function(){
return gulp.src(path.src.vendor_img)
.pipe(imagemin({
progressive: true,
interlaced: true,
use: [pngguant()]
}))
.pipe(gulp.dest(path.build.img))
});
gulp.task('vendor:fonts', function() {
gulp.src(path.src.vendor_fonts)
.pipe(gulp.dest(path.build.fonts))
});
Answer the question
In order to leave comments, you need to log in
1. The pattern in src is divided into two parts base + relative (base is everything up to the asterisks, relative is the rest)
2. The final path in dest is written as relative
3. base can be changed by specifying the base option in src() (gulp.src ('a/**/b', {base: '.'}))
Based on these points - set the correct pattern or set the desired base option.
If you have a problem with the paths to fonts (images) in the final css, instead of url('images/etc') you need url('../images/etc), then here you need to look for the gulp plugin on request "rebase" (or postcss plugin )
Before you shit code in gulp
The answer to your question in the third lesson is vynil fs streams.
var rename = require("gulp-rename")
gulp.task('vendor:img', function(){
return gulp.src(path.src.vendor_img)
.pipe(imagemin({
progressive: true,
interlaced: true,
use: [pngguant()]
}))
.pipe(rename(function (path){
path.dirname = 'build/'
}))
.pipe(gulp.dest(path.build.img))
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question