@tanem/archiver-webpack-plugin

A webpack plugin that generates zip archives.


Keywords
archive, archiver, javascript, plugin, webpack, zip
License
MIT
Install
npm install @tanem/archiver-webpack-plugin@6.0.23

Documentation

archiver-webpack-plugin

npm version build status coverage status npm downloads

A webpack plugin that uses node-archiver to generate .zip, .tar, .tar.gz, or jar archives when the build is done.

Basic Usage

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')],
}

API

Arguments

  • format - The archive format. One of zip, tar or jar.
  • 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 the node-glob defaults, but sets cwd to the output path. Any globOptions 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: '*',
    }),
  ],
}

Installation

⚠️ 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.

License

MIT