1.1.7 • Published 4 years ago
imgtransferbase64 v1.1.7
imgTransferBase64
introduction
The plug in developed based on gulp can convert the embedded pictures (pictures less than 5KB) in HTML and CSS files into Base64 format
Installation tutorial
npm install imgTransferBase64 -D
Precautions
It supports buffer and cannot use stream. By default, pictures larger than 5KB will not be compiled
// Plug in content default configuration
this.ls = option.size || '5'; // Threshold value of image file conversion, in kilobytes
this.hr = option.htmlRegular || /(<img.+src=["|'])(.*?\.png|jpe?g|gif)(["|'].*?>)/gi; // Image tag filter regular
this.cr = option.cssRegular || /background-image:.*?url\(.*?\)/gi; // CSS file filtering regular
this.cssExtname = option.cssExtname || ['css', 'scss', 'less', 'stylus', 'sass']; // Set the CSS file type to be filtered
this.htmlExtname = option.htmlExtname || ['html', 'vue', 'ejs']; // Set the HTML file type to be filtered
// The configuration can be customized, that is, the option is passed in when the plug-in object is instantiated
var Transfer = require('imgtransferbase64');
var i = new Transfer({
size: '',
htmlRegular: /RegExp/,
cssRegular: /RegExp/,
cssExtname: [],
htmlExtname: []
})
instruction for use
var gulp = require('gulp');
var path = require('path');
var Transfer = require('imgtransferbase64');
var iToB = new Transfer(optionObj);
gulp.task('transfer', (cb) => {
gulp.src(path.join(__dirname, 'test', '**', '*'))
.pipe(iToB.transfer())
.pipe(gulp.dest('./dist'));
cb()
});