Answer the question
In order to leave comments, you need to log in
How to enable html-minifier plugin for gulp?
I want to include the html-minifier
plugin in gulp
There is a similar plugin like gulp-html-minifier or htmlnano but it's much better to get new updates directly.
Maybe this plugin can help somehow, but I haven't figured it out yet... vinyl-source-stream
This code doesn't work with htmlMinify.
The return value is not a function it tells me pointing to different lines in this plugin.
const htmlMinify = require('html-minifier').minify
function html() {
const options = {
includeAutoGeneratedTags: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortClassName: true,
useShortDoctype: true
}
return src(config.app.html)
.pipe(htmlMinify(options))
.pipe(dest(config.build.html))
}
exports.stream = series(clear, html, stream)
Answer the question
In order to leave comments, you need to log in
I wrote the code to make this plugin work with gulp.
There is no need to use third party plugins anymore.
const { src, dest, series } = require('gulp');
const htmlMinify = require('html-minifier');
const options = {
includeAutoGeneratedTags: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortClassName: true,
useShortDoctype: true,
collapseWhitespace: true
};
function gHtmlMinify() {
return src('app/**/*.html')
.on('data', function(file) {
const buferFile = Buffer.from(htmlMinify.minify(file.contents.toString(), options))
file.contents = buferFile;
console.log(file);
return;
})
.pipe(dest('build'))
}
exports.gHtmlMinify = series(gHtmlMinify);
Since no one helped, tip *
Plugins for GULP not in vain put that they are for gulp.
src, pipe - they can only work with data transformed in a special way.
Make the src command console - this is what other commands / plugins
use.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question