# parallel-webpack

> Builds multiple webpack configurations in parallel and allows you to easily create variants to those configurations.

Latest version **2.6.0** (published 2020-04-08) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install parallel-webpack
pnpm add parallel-webpack
yarn add parallel-webpack
bun add parallel-webpack
```

Provides the command `parallel-webpack`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.6.0 |
| Published | 2020-04-08 |
| First published | 2015-12-14 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 94.2 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Patrick Gotthardt |
| Maintainers | eyalaman, pago |
| Keywords | webpack, parallel |

## Links

- npm: https://www.npmjs.com/package/parallel-webpack
- Repository: https://github.com/trivago/parallel-webpack
- Homepage: https://github.com/trivago/parallel-webpack#readme
- Issues: https://github.com/trivago/parallel-webpack/issues
- npm.io page: https://npm.io/package/parallel-webpack

## Dependencies (12)

- [ajv](https://npm.io/package/ajv.md) ^4.9.2
- [chalk](https://npm.io/package/chalk.md) ^1.1.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.0.6
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [node-ipc](https://npm.io/package/node-ipc.md) ^9.1.0
- [interpret](https://npm.io/package/interpret.md) ^1.0.1
- [pluralize](https://npm.io/package/pluralize.md) ^1.2.1
- [worker-farm](https://npm.io/package/worker-farm.md) ^1.3.1
- [lodash.assign](https://npm.io/package/lodash.assign.md) ^4.0.8
- [lodash.flatten](https://npm.io/package/lodash.flatten.md) ^4.2.0
- [supports-color](https://npm.io/package/supports-color.md) ^3.1.2
- [lodash.endswith](https://npm.io/package/lodash.endswith.md) ^4.0.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.6.0 (latest) — 2020-04-08
- 3.0.0-alpha.2 (alpha) — 2018-01-30
- 2.5.0 — 2020-04-03
- 2.4.0 — 2019-06-03
- 2.3.0 — 2018-02-26
- 2.2.0 — 2017-09-19
- 2.1.0 — 2017-07-28
- 2.0.0 — 2017-06-28
- 1.6.1 — 2017-01-20
- 1.6.0 — 2016-12-16
- 1.5.0 — 2016-06-14
- 1.4.0 — 2016-05-10
- 1.3.1 — 2016-02-16
- 1.3.0 — 2016-01-26
- 1.2.0 — 2016-01-11
- … 3 more at https://npm.io/package/parallel-webpack/versions

## README

[![npm version](https://badge.fury.io/js/parallel-webpack.svg)](https://badge.fury.io/js/parallel-webpack)
[![Build Status](https://travis-ci.org/trivago/parallel-webpack.svg?branch=master)](https://travis-ci.org/trivago/parallel-webpack) [![CircleCI](https://circleci.com/gh/trivago/parallel-webpack.svg?style=svg)](https://circleci.com/gh/trivago/parallel-webpack) [![Coverage Status](https://coveralls.io/repos/github/trivago/parallel-webpack/badge.svg?branch=coverage)](https://coveralls.io/github/trivago/parallel-webpack?branch=coverage)
[![Install Size](https://packagephobia.now.sh/badge?p=parallel-webpack)](https://packagephobia.now.sh/result?p=parallel-webpack)
# parallel-webpack - Building multi-configs in parallel

`parallel-webpack` allows you to run multiple webpack builds in parallel,
spreading the work across your processors and thus helping to significantly speed
up your build. For us at [trivago](http://www.trivago.com) it has reduced
the build from 16 minutes to just 2 minutes - for 32 variants. That performance
improvement naturally comes at the expense of utilizing all available CPU cores.

## Installation

```sh
npm install parallel-webpack --save-dev
```

You can choose whether to install `parallel-webpack` globally or locally.
At [trivago](http://www.trivago.com), we keep our build tools locally to the project
so that we have full control over its versions.

## Basic example

Given a `webpack.config.js` like this:

```javascript
var path = require('path');
module.exports = [{
    entry: './pageA.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'pageA.bundle.js'
    }
}, {
    entry: './pageB.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'pageB.bundle.js'
    }
}];
```

`parallel-webpack` will run both specified builds in parallel.

## Variants example

Sometimes, just using different configurations like above won't be enough and what
you really want or need is the same configuration with some adjustments.
`parallel-webpack` can help you with generating those `configuration variants` as
well.

```javascript
var createVariants = require('parallel-webpack').createVariants;

// Those options will be mixed into every variant
// and passed to the `createConfig` callback.
var baseOptions = {
    preferredDevTool: process.env.DEVTOOL || 'eval'
};

// This object defines the potential option variants
// the key of the object is used as the option name, its value must be an array
// which contains all potential values of your build.
var variants = {
    minified: [true, false],
    debug: [true, false],
    target: ['commonjs2', 'var', 'umd', 'amd']
};

function createConfig(options) {
    var plugins = [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.DefinePlugin({
            DEBUG: JSON.stringify(JSON.parse(options.debug))
        })
    ];
    if(options.minified) {
        plugins.push(new webpack.optimize.UglifyJsPlugin({
            sourceMap: false,
            compress: {
                warnings: false
            }
        }));
    }
    return {
        entry: './index.js',
        devtool: options.preferredDevTool,
        output: {
            path: './dist/',
            filename: 'MyLib.' +
                options.target +
                (options.minified ? '.min' : '') +
                (options.debug ? '.debug' : '')
                + '.js',
            libraryTarget: options.target
        },
        plugins: plugins
    };
}

module.exports = createVariants(baseOptions, variants, createConfig);
```

The above configuration will create 16 variations of the build for you, which
`parallel-webpack` will distribute among your processors for building.

```
[WEBPACK] Building 16 targets in parallel
[WEBPACK] Started building MyLib.umd.js
[WEBPACK] Started building MyLib.umd.min.js
[WEBPACK] Started building MyLib.umd.debug.js
[WEBPACK] Started building MyLib.umd.min.debug.js

[WEBPACK] Started building MyLib.amd.js
[WEBPACK] Started building MyLib.amd.min.js
[WEBPACK] Started building MyLib.amd.debug.js
[WEBPACK] Started building MyLib.amd.min.debug.js

[WEBPACK] Started building MyLib.commonjs2.js
[WEBPACK] Started building MyLib.commonjs2.min.js
[WEBPACK] Started building MyLib.commonjs2.debug.js
[WEBPACK] Started building MyLib.commonjs2.min.debug.js

[WEBPACK] Started building MyLib.var.js
[WEBPACK] Started building MyLib.var.min.js
[WEBPACK] Started building MyLib.var.debug.js
[WEBPACK] Started building MyLib.var.min.debug.js
```

## Running the watcher

One of the features that made webpack so popular is certainly its watcher which
continously rebuilds your application.

When using `parallel-webpack`, you can easily use the same feature as well by
specifying the `--watch` option on the command line:

```
parallel-webpack --watch
```

## Specifying retry limits

As a side-effect of using `parallel-webpack`, an error will no longer lead to
you having to restart webpack. Instead, `parallel-webpack` will keep retrying to
build your application until you've fixed the problem.

While that is highly useful for development it can be a nightmare for
CI builds. Thus, when building with `parallel-webpack` in a CI context, you should
consider to use the `--max-retries` (or `-m` option) to force `parallel-webpack` to give
up on your build after a certain amount of retries:

```
parallel-webpack --max-retries=3
```

## Specifying the configuration file

When you need to use a configuration file that is not `webpack.config.js`, you can
specify its name using the `--config` parameter:

```
parallel-webpack --config=myapp.webpack.config.js
```

## Switch off statistics (improves performance)

While the statistics generated by Webpack are very usually very useful, they also
take time to generate and print and create a lot of visual overload if you don't
actually need them.

Since version *1.3.0*, generating them can be turned off:

```
parallel-webpack --no-stats
```

## Limiting parallelism

Under certain circumstances you might not want `parallel-webpack` to use all of your
available CPUs for building your assets. In those cases, you can specify the `parallel`,
or `p` for short, option to tell `parallel-webpack` how many CPUs it may use.

```
parallel-webpack -p=2
```


## Configurable configuration

Sometimes, you might want to access command line arguments within your `webpack.config.js`
in order to create a more specific configuration.

`parallel-webpack` will forward every parameter specified after `--` to the configuration
as is:

```
parallel-webpack -- --app=trivago
```


Within `webpack.config.js`:

```
console.log(process.argv);
// => [ 'node', 'parallel-webpack', '--app=trivago' ]
```

`parallel-webpack` adds the first two values to `process.argv` to ensure that there
are no differences between various ways of invoking the `webpack.config.js`.

## Node.js API

Just like webpack, you can also use `parallel-webpack` as an API from node.js
(You can specify any other option used in [worker-farm](https://www.npmjs.com/package/worker-farm)):

```javascript
var run = require('parallel-webpack').run,
    configPath = require.resolve('./webpack.config.js');

run(configPath, {
    watch: false,
    maxRetries: 1,
    stats: true, // defaults to false
    maxConcurrentWorkers: 2 // use 2 workers
});
```

You can pass a notify callback as well.
```javascript
var run = require('parallel-webpack').run,
    configPath = require.resolve('./webpack.config.js'),
    options = {/*...*/};

function notify() {
// do things
}

run(configPath, options, notify);
```
**NOTE:** In watch mode notify callback provided with Node.js API will run **only once**
when all of the builds are finished.

### createVariants

---

#### createVariants(baseConfig: Object, variants: Object, configCallback: Function): Object[]

Alters the given `baseConfig` with all possible `variants` and maps the result into
a valid webpack configuration using the given `configCallback`.

#### createVariants(variants: Object, configCallback: Function): Object[]

Creates all possible variations as specified in the `variants` object and
maps the result into a valid webpack configuration using the given `configCallback`.

#### createVariants(baseConfig: Object, variants: Object): Object[]

Alters the given `baseConfig` with all possible `variants` and returns it.

#### createVariants(variants: Object): Object[]

Creates all possible variations from the given `variants` and returns them as a flat array.

---
_Source: https://npm.io/package/parallel-webpack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
