Answer the question
In order to leave comments, you need to log in
Gulp-imagemin cut content of SVG file?
let project_folder = "dist";
let source_folder = "src";
let path = {
build: {
html: project_folder + "/",
css: project_folder + "/css/",
js: project_folder + "/js/",
img: project_folder + "/img/"
//fonts: project_folder + "/fonts/"
},
src: {
html: [source_folder + "/*.html", "!" + source_folder + "/_*.html"],
css: source_folder + "/scss/style.scss",
js: source_folder + "/js/custom.js",
img: source_folder + "/img/**/*.{gif,jpg,png,webp,svg,ico}"
//fonts: source_folder + "/fonts/"
},
watch: {
html: source_folder + "/**/*.html",
css: source_folder + "/scss/**/*.scss",
js: source_folder + "/js/**/*.js",
img: source_folder + "/img/**/*.{gif,jpg,png,webp,svg,ico}"
},
clean: "./" + project_folder + "/"
}
let { src, dest } = require('gulp'),
gulp = require('gulp'),
browsersync = require('browser-sync').create(),
fileinclude = require('gulp-file-include'),
del = require('del'),
scss = require('gulp-sass')(require('sass')),
autoprefixer = require('gulp-autoprefixer'),
group_media = require('gulp-group-css-media-queries'),
clean_css = require('gulp-clean-css'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify-es').default,
imagemin = require('gulp-imagemin'),
webp = require('gulp-webp');
function browserSync(params) {
browsersync.init({
server: {
baseDir: "./" + project_folder + "/"
},
port: 3000,
notify: false
})
}
function html() {
return src(path.src.html)
.pipe(fileinclude())
.pipe(dest(path.build.html))
.pipe(browsersync.stream())
}
function css() {
return src(path.src.css)
.pipe(
scss({
outputStyle: "expanded"
})
)
.pipe(group_media())
.pipe(
autoprefixer({
overrideBrowserslist: ["last 5 versions"],
cascade: true
})
)
.pipe(dest(path.build.css))
.pipe(clean_css())
.pipe(
rename({
extname: ".min.css"
})
)
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}
function js() {
return src(path.src.js)
.pipe(fileinclude())
.pipe(dest(path.build.js))
.pipe(uglify())
.pipe(
rename({
extname: ".min.js"
})
)
.pipe(dest(path.build.js))
.pipe(browsersync.stream())
}
function images() {
return src(path.src.img)
.pipe(
webp({
quality: 70
})
)
.pipe(dest(path.build.img))
.pipe(src(path.src.img))
.pipe(
imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}],
interlaced: true,
optimizationLevel: 3
})
)
.pipe(dest(path.build.img))
.pipe(browsersync.stream())
}
function watchFiles(params) {
gulp.watch([path.watch.html], html);
gulp.watch([path.watch.css], css);
gulp.watch([path.watch.js], js);
gulp.watch([path.watch.img], images);
}
function clean(params) {
return del(path.clean);
}
let build = gulp.series(clean, gulp.parallel(html, css, js, images));
let watch = gulp.parallel(build, watchFiles, browserSync);
exports.html = html;
exports.css = css;
exports.js = js;
exports.images = images;
exports.build = build;
exports.watch = watch;
exports.default = watch;
<svg aria-hidden="true">
<symbol id="i-stupid" viewBox="0 0 36 36">
<path d="M33.642 14.648c1.85 8.638-3.651 17.142-12.29 18.994-8.638 1.85-17.142-3.651-18.994-12.29C.508 12.714 6.01 4.21 14.648 2.36 23.286.507 31.79 6.009 33.642 14.648z" fill="#FFC25C"/><path d="M28.033 10.009a5.985 5.985 0 11-11.703 2.507 5.985 5.985 0 0111.703-2.507z" fill="#F4F7F9"/><path d="M21.83 12.067a1.81 1.81 0 100-3.62 1.81 1.81 0 000 3.62z" fill="#292F33"/><path d="M14.525 14.692a3.5 3.5 0 11-6.844 1.466 3.5 3.5 0 016.844-1.466z" fill="#F4F7F9"/><path d="M11.466 17.78a1.726 1.726 0 10-.724-3.376 1.726 1.726 0 00.724 3.375z" fill="#292F33"/><path d="M18.558 20.607c-3.149.674-5.316.755-8.008.807-.614.013-1.737.372-1.365 2.11.745 3.476 5.67 6.965 11.236 5.773 5.565-1.193 8.627-6.394 7.883-9.87-.373-1.738-1.546-1.606-2.111-1.365-2.476 1.055-4.486 1.87-7.635 2.545z" fill="#65471B"/><path d="M11.781 23.332v5.333c0 2.666 1.778 5.332 5.333 5.332s5.332-2.666 5.332-5.332v-5.332H11.781z" fill="#E8596E"/><path d="M17.114 30.335a.484.484 0 00.485-.485v-5.594h-.97v5.594c0 .268.218.485.485.485z" fill="#DD2F45"/><path d="M10.924 23.152s2.793.31 8.007-.807c5.214-1.117 7.635-2.545 7.635-2.545s-.992 3.848-7.076 5.152c-6.083 1.303-8.566-1.8-8.566-1.8z" fill="#fff"/>
</symbol>
<symbol id="i-exciting" viewBox="0 0 36 36">
<path d="M34 18c0 8.836-7.164 16-16 16S2 26.836 2 18 9.164 2 18 2s16 7.164 16 16z" fill="#FFC25C"/><path d="M12.222 19.778c1.228 0 2.222-1.393 2.222-3.111 0-1.719-.995-3.112-2.222-3.112-1.227 0-2.222 1.393-2.222 3.112 0 1.718.995 3.11 2.222 3.11zM23.777 19.778c1.227 0 2.222-1.393 2.222-3.111 0-1.719-.995-3.112-2.222-3.112-1.227 0-2.222 1.393-2.222 3.112 0 1.718.995 3.11 2.222 3.11zM22.876 26.781c-.01-.039-1.017-3.892-4.875-3.892s-4.866 3.853-4.875 3.892a.44.44 0 00.206.484c.166.1.384.076.53-.053.008-.008.9-.767 4.139-.767 3.19 0 4.104.737 4.139.767a.445.445 0 00.736-.43z" fill="#664500"/><path d="M10.889 28.667a4.444 4.444 0 11-8.889 0c0-2.456 3.556-8.89 4.444-8.89.89 0 4.445 6.434 4.445 8.89z" fill="#5DADEC"/><path d="M18 11.778c7.777 0 14.252 4.008 15.694 9.319C33.892 20.094 34 19.06 34 18c0-8.836-7.164-16-16-16S2 9.164 2 18c0 1.06.11 2.094.306 3.097 1.442-5.311 7.918-9.32 15.694-9.32z" fill="#BDDDF4"/><path d="M28.668 12.667c-4.937 0-6.936-3.882-7.018-4.047a.89.89 0 011.588-.8c.067.13 1.619 3.069 5.43 3.069a.889.889 0 110 1.778zm-21.334 0a.89.89 0 010-1.778c4.518 0 5.33-2.773 5.363-2.892a.894.894 0 011.083-.63.885.885 0 01.639 1.071c-.044.173-1.126 4.229-7.085 4.229z" fill="#664500"/>
</symbol>
<symbol id="i-touching" viewBox="0 0 36 36">
<path d="M34 18c0 8.836-7.164 16-16 16S2 26.836 2 18 9.164 2 18 2s16 7.164 16 16z" fill="#FFC25C"/><path d="M7.335 18.889a.888.888 0 01-.534-1.6c.127-.094 2.623-1.94 6.094-2.606-2.2-1.104-4.641-1.127-4.672-1.127a.89.89 0 010-1.778c.197 0 4.847.034 7.74 2.927a.889.889 0 01-.628 1.517c-4.1 0-7.434 2.464-7.467 2.49a.886.886 0 01-.533.177zm21.332-.001a.887.887 0 01-.532-.176c-.033-.026-3.387-2.49-7.467-2.49a.888.888 0 01-.629-1.517c2.895-2.893 7.543-2.927 7.74-2.927a.888.888 0 01.002 1.777c-.032 0-2.474.024-4.674 1.128 3.471.666 5.967 2.51 6.093 2.607a.889.889 0 01-.533 1.598zm-12.444 8.89c1.778-4.445 11.556-4.445 11.556-2.667 0 .889-7.111-.889-11.556 2.667z" fill="#664500"/><path d="M18.36 18.03c2.381 2.378-3.531 13.798-4.666 14.933-.933.933-3.733.933-4.666-.934-.934-1.866-3.734 0-4.667-.933-1.867-1.867.933-2.8 0-4.667-.933-1.866-2.8-2.8-.933-4.666 1.866-1.867 6.533-.934 9.333-2.8 2.8-1.867 4.666-1.867 5.6-.934z" fill="#CCD6DD"/><path d="M17.397 19.664c-.014-.055-.047-.1-.07-.151-.027-.059-.045-.12-.084-.173a.926.926 0 00-.617-.368.948.948 0 00-.361.02c-.081.02-.15.062-.222.103-.034.019-.07.027-.102.05a.937.937 0 00-.247.271c-2.608 4.347-8.837 7.061-8.9 7.089a.933.933 0 00.736 1.716c.198-.086 3.604-1.574 6.6-4.189-1.839 3.4-4.65 5.329-4.688 5.356a.934.934 0 001.038 1.552c.242-.162 5.958-4.043 6.94-10.91a.974.974 0 00-.023-.366z" fill="#F5F8FA"/>
</symbol>
</svg>
<svg aria-hidden="true"></svg>
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