-
Is there any way to use node.js plugins with gulp? |
Beta Was this translation helpful? Give feedback.
Answered by
brendan8c
Jul 1, 2021
Replies: 2 comments 1 reply
-
Write JS code for each plugin. 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 test12() {
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.test12 = series(test12); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
brendan8c
-
There's an example on gulp getting started documentation as well which using // source: https://gulpjs.com/docs/en/getting-started/using-plugins/#inline-plugins
const { src, dest } = require('gulp');
const uglify = require('uglify-js');
const through2 = require('through2');
exports.default = function() {
return src('src/*.js')
// Instead of using gulp-uglify, you can create an inline plugin
.pipe(through2.obj(function(file, _, cb) {
if (file.isBuffer()) {
const code = uglify.minify(file.contents.toString())
file.contents = Buffer.from(code.code)
}
cb(null, file);
}))
.pipe(dest('output/'));
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write JS code for each plugin.
Here is an example of how I adapted the 'html-minifier' plugin for gulp