@hidoo/gulp-plugin-compress
v1.0.0-alpha.1
Published
Plugin to compress text data for gulp.
Downloads
21
Maintainers
Readme
@hidoo/gulp-plugin-compress
Plugin to compress text data for gulp.
Installation
npm install --save-dev gulp @hidoo/gulp-plugin-compress
Usage
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
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
options
defaultOptions option (optional, default{}
)options.gzip
(Boolean | gzipOptions) gzip compression options (optional, defaultgzipOptions
)options.brotli
(Boolean | brotliOptions) brotli compression options (optional, defaultbrotliOptions
)options.append
Boolean append compressed files before original files whether or not (optional, defaulttrue
)options.keepExtname
Boolean keep original extension name whether or not (like: example.html.gz) (optional, defaulttrue
)options.targetExtnames
Boolean list of target extension names to compress (optional, default['.html','.css','.js','.svg','.txt']
)options.verbose
Boolean 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 test
License
MIT