A webpack plugin that uses node-archiver to generate
.zip
,.tar
,.tar.gz
, orjar
archives when the build isdone
.
const { ArchiverWebpackPlugin } = require('@tanem/archiver-webpack-plugin')
const path = require('path')
module.exports = {
mode: 'development',
entry: './foo.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'foo.bundle.js',
},
plugins: [new ArchiverWebpackPlugin('zip')],
}
Arguments
-
format
- The archive format. One ofzip
,tar
orjar
. -
options
- Optional An object containing the optional arguments defined below. Defaults to{}
.-
destpath
- Optional The destination path within the archive. Defaults to''
, which means files are output to the root of the archive. -
filename
- Optional The name of the archive.'.zip'
,'.tar'
,'.tar.gz'
or'.jar'
will be appended where appropriate. Defaults to the basename of the webpack output path. -
formatOptions
- Optional Allows fine-tuning of archiving. Defaults to the archiver defaults. -
globOptions
- Optional The glob options that will change pattern matching behaviour. Defaults to thenode-glob
defaults, but setscwd
to the output path. AnyglobOptions
passed will take precedence. -
globPattern
- Optional The glob pattern that determines what will be included in the archive. Defaults to'**/*'
which will include all files in the output path.
-
Example
const { ArchiverWebpackPlugin } = require('@tanem/archiver-webpack-plugin')
const path = require('path')
module.exports = {
mode: 'development',
entry: './foo.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'foo.bundle.js',
},
plugins: [
new ArchiverWebpackPlugin('tar', {
destpath: 'foo',
filename: 'bar-baz',
formatOptions: { gzip: true },
globOptions: { dot: true, ignore: '*.map' },
globPattern: '*',
}),
],
}
⚠️ This library requires webpack 4 and Node.js >= 16.
$ npm install @tanem/archiver-webpack-plugin --save-dev
If you use Node.js >= 17 you'll also need to set an environment variable by running the following command at the prompt, or by adding it to your shell profile:
export NODE_OPTIONS=--openssl-legacy-provider
Ref: webpack/webpack#14532.
MIT