1.0.0-alpha.4 • Published 6 months ago
@hidoo/gulp-plugin-compress v1.0.0-alpha.4
@hidoo/gulp-plugin-compress
Plugin to compress text data for gulp.
Installation
npm install --save-dev gulp @hidoo/gulp-plugin-compressUsage
import gulp from 'gulp';
import compress from '@hidoo/gulp-plugin-compress';
export const compressTask = () =>
gulp.src('/path/to/src').pipe(compress()).pipe(gulp.dest('/path/to/dest'));API
compressors
Mapping of promisified compressor.
Type: Object
Properties
gzipFunction[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) gzip compressor functionbrotliFunction[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) brotli compressor function
Examples
import fs from 'node:fs/promises';
import { compressors } from '@hidoo/gulp-plugin-compress';
const buffer = await fs.readFile('./path/to/file.ext');
const compressed = await compressors.gzip(buffer);gzip
brotli
defaultOptions
Default options.
Type: Object
gzip
brotli
append
keepExtname
targetExtnames
verbose
compress
Generate compressed files.
Parameters
optionsdefaultOptions option (optional, default{})options.gzip(Boolean | gzipOptions) gzip compression options (optional, defaultgzipOptions)options.brotli(Boolean | brotliOptions) brotli compression options (optional, defaultbrotliOptions)options.appendBoolean append compressed files before original files whether or not (optional, defaulttrue)options.keepExtnameBoolean keep original extension name whether or not (like: example.html.gz) (optional, defaulttrue)options.targetExtnamesBoolean list of target extension names to compress (optional, default['.html','.css','.js','.svg','.txt'])options.verboseBoolean output log whether or not (optional, defaultfalse)
Examples
import gulp from 'gulp';
import compress from '@hidoo/gulp-plugin-compress';
export const compressTask = () =>
gulp
.src('/path/to/src')
.pipe(
compress({
gzip: true,
brotli: false,
append: false,
keepExtname: false,
targetExtnames: ['.html', '.css', '.js'],
verbose: true
})
)
.pipe(gulp.dest('/path/to/dest'));Test
pnpm testLicense
MIT