Answer the question
In order to leave comments, you need to log in
How to not copy images translated to base64 in gulp?
Today is the first day since I started to deal with the assembly of projects using Gulp, so do not kick much.
Using gulp-css-base64 , images smaller than 50Kb are converted to base64 in css.
How can I make sure that the image files processed in this way are not copied to the folder with the built project, but remain only in src?
My gulpfile.js
'use strict';
var gulp = require('gulp'),
watch = require('gulp-watch'),
rigger = require('gulp-rigger'),
cssBase64 = require('gulp-css-base64');
var path = {
build: {
html: 'build/',
js: 'build/js/',
css: 'build/css/',
img: 'build/img/',
fonts: 'build/fonts/'
},
src: {
html: 'src/*.html',
js: 'src/js/*.js',
style: 'src/css/*.css',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*'
},
watch: {
html: 'src/**/*.html',
js: 'src/js/**/*.js',
style: 'src/css/**/*.css',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*'
},
clean: './build'
};
gulp.task('clean', function (cb) {
rimraf(path.clean, cb);
});
gulp.task('html:build', function () {
gulp.src(path.src.html)
.pipe(rigger())
.pipe(gulp.dest(path.build.html));
});
gulp.task('js:build', function () {
gulp.src(path.src.js)
.pipe(rigger())
.pipe(gulp.dest(path.build.js));
});
gulp.task('style:build', function () {
gulp.src(path.src.style)
.pipe(cssBase64({
maxWeightResource: 5000, //Размер файла в bytes
extensionsAllowed: ['.gif', '.jpg', '.png']
}))
.pipe(gulp.dest(path.build.css));
});
gulp.task('image:build', function () {
gulp.src(path.src.img)
.pipe(gulp.dest(path.build.img));
});
gulp.task('fonts:build', function() {
gulp.src(path.src.fonts)
.pipe(gulp.dest(path.build.fonts))
});
gulp.task('build', [
'html:build',
'js:build',
'style:build',
'fonts:build',
'image:build'
]);
gulp.task('watch', function(){
watch([path.watch.html], function(event, cb) {
gulp.start('html:build');
});
watch([path.watch.style], function(event, cb) {
gulp.start('style:build');
});
watch([path.watch.js], function(event, cb) {
gulp.start('js:build');
});
watch([path.watch.img], function(event, cb) {
gulp.start('image:build');
});
watch([path.watch.fonts], function(event, cb) {
gulp.start('fonts:build');
});
});
gulp.task('default', ['build', 'watch']);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question