{"id":13653262,"url":"https://github.com/trivago/parallel-webpack","last_synced_at":"2025-04-23T06:31:28.930Z","repository":{"id":42950829,"uuid":"47754695","full_name":"trivago/parallel-webpack","owner":"trivago","description":"Builds multi-config webpack projects in parallel","archived":true,"fork":false,"pushed_at":"2022-01-25T15:37:34.000Z","size":177,"stargazers_count":1482,"open_issues_count":37,"forks_count":96,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-20T02:34:15.175Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trivago.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-10T10:27:04.000Z","updated_at":"2024-12-14T12:38:32.000Z","dependencies_parsed_at":"2022-09-26T17:00:42.469Z","dependency_job_id":null,"html_url":"https://github.com/trivago/parallel-webpack","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivago%2Fparallel-webpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivago%2Fparallel-webpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivago%2Fparallel-webpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivago%2Fparallel-webpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trivago","download_url":"https://codeload.github.com/trivago/parallel-webpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250384963,"owners_count":21421828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T02:01:08.021Z","updated_at":"2025-04-23T06:31:23.917Z","avatar_url":"https://github.com/trivago.png","language":"JavaScript","readme":"[![npm version](https://badge.fury.io/js/parallel-webpack.svg)](https://badge.fury.io/js/parallel-webpack)\n[![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)\n[![Install Size](https://packagephobia.now.sh/badge?p=parallel-webpack)](https://packagephobia.now.sh/result?p=parallel-webpack)\n# parallel-webpack - Building multi-configs in parallel\n\n`parallel-webpack` allows you to run multiple webpack builds in parallel,\nspreading the work across your processors and thus helping to significantly speed\nup your build. For us at [trivago](http://www.trivago.com) it has reduced\nthe build from 16 minutes to just 2 minutes - for 32 variants. That performance\nimprovement naturally comes at the expense of utilizing all available CPU cores.\n\n## Installation\n\n```sh\nnpm install parallel-webpack --save-dev\n```\n\nYou can choose whether to install `parallel-webpack` globally or locally.\nAt [trivago](http://www.trivago.com), we keep our build tools locally to the project\nso that we have full control over its versions.\n\n## Basic example\n\nGiven a `webpack.config.js` like this:\n\n```javascript\nvar path = require('path');\nmodule.exports = [{\n    entry: './pageA.js',\n    output: {\n        path: path.resolve(__dirname, './dist'),\n        filename: 'pageA.bundle.js'\n    }\n}, {\n    entry: './pageB.js',\n    output: {\n        path: path.resolve(__dirname, './dist'),\n        filename: 'pageB.bundle.js'\n    }\n}];\n```\n\n`parallel-webpack` will run both specified builds in parallel.\n\n## Variants example\n\nSometimes, just using different configurations like above won't be enough and what\nyou really want or need is the same configuration with some adjustments.\n`parallel-webpack` can help you with generating those `configuration variants` as\nwell.\n\n```javascript\nvar createVariants = require('parallel-webpack').createVariants;\n\n// Those options will be mixed into every variant\n// and passed to the `createConfig` callback.\nvar baseOptions = {\n    preferredDevTool: process.env.DEVTOOL || 'eval'\n};\n\n// This object defines the potential option variants\n// the key of the object is used as the option name, its value must be an array\n// which contains all potential values of your build.\nvar variants = {\n    minified: [true, false],\n    debug: [true, false],\n    target: ['commonjs2', 'var', 'umd', 'amd']\n};\n\nfunction createConfig(options) {\n    var plugins = [\n        new webpack.optimize.DedupePlugin(),\n        new webpack.optimize.OccurenceOrderPlugin(),\n        new webpack.DefinePlugin({\n            DEBUG: JSON.stringify(JSON.parse(options.debug))\n        })\n    ];\n    if(options.minified) {\n        plugins.push(new webpack.optimize.UglifyJsPlugin({\n            sourceMap: false,\n            compress: {\n                warnings: false\n            }\n        }));\n    }\n    return {\n        entry: './index.js',\n        devtool: options.preferredDevTool,\n        output: {\n            path: './dist/',\n            filename: 'MyLib.' +\n                options.target +\n                (options.minified ? '.min' : '') +\n                (options.debug ? '.debug' : '')\n                + '.js',\n            libraryTarget: options.target\n        },\n        plugins: plugins\n    };\n}\n\nmodule.exports = createVariants(baseOptions, variants, createConfig);\n```\n\nThe above configuration will create 16 variations of the build for you, which\n`parallel-webpack` will distribute among your processors for building.\n\n```\n[WEBPACK] Building 16 targets in parallel\n[WEBPACK] Started building MyLib.umd.js\n[WEBPACK] Started building MyLib.umd.min.js\n[WEBPACK] Started building MyLib.umd.debug.js\n[WEBPACK] Started building MyLib.umd.min.debug.js\n\n[WEBPACK] Started building MyLib.amd.js\n[WEBPACK] Started building MyLib.amd.min.js\n[WEBPACK] Started building MyLib.amd.debug.js\n[WEBPACK] Started building MyLib.amd.min.debug.js\n\n[WEBPACK] Started building MyLib.commonjs2.js\n[WEBPACK] Started building MyLib.commonjs2.min.js\n[WEBPACK] Started building MyLib.commonjs2.debug.js\n[WEBPACK] Started building MyLib.commonjs2.min.debug.js\n\n[WEBPACK] Started building MyLib.var.js\n[WEBPACK] Started building MyLib.var.min.js\n[WEBPACK] Started building MyLib.var.debug.js\n[WEBPACK] Started building MyLib.var.min.debug.js\n```\n\n## Running the watcher\n\nOne of the features that made webpack so popular is certainly its watcher which\ncontinously rebuilds your application.\n\nWhen using `parallel-webpack`, you can easily use the same feature as well by\nspecifying the `--watch` option on the command line:\n\n```\nparallel-webpack --watch\n```\n\n## Specifying retry limits\n\nAs a side-effect of using `parallel-webpack`, an error will no longer lead to\nyou having to restart webpack. Instead, `parallel-webpack` will keep retrying to\nbuild your application until you've fixed the problem.\n\nWhile that is highly useful for development it can be a nightmare for\nCI builds. Thus, when building with `parallel-webpack` in a CI context, you should\nconsider to use the `--max-retries` (or `-m` option) to force `parallel-webpack` to give\nup on your build after a certain amount of retries:\n\n```\nparallel-webpack --max-retries=3\n```\n\n## Specifying the configuration file\n\nWhen you need to use a configuration file that is not `webpack.config.js`, you can\nspecify its name using the `--config` parameter:\n\n```\nparallel-webpack --config=myapp.webpack.config.js\n```\n\n## Switch off statistics (improves performance)\n\nWhile the statistics generated by Webpack are very usually very useful, they also\ntake time to generate and print and create a lot of visual overload if you don't\nactually need them.\n\nSince version *1.3.0*, generating them can be turned off:\n\n```\nparallel-webpack --no-stats\n```\n\n## Limiting parallelism\n\nUnder certain circumstances you might not want `parallel-webpack` to use all of your\navailable CPUs for building your assets. In those cases, you can specify the `parallel`,\nor `p` for short, option to tell `parallel-webpack` how many CPUs it may use.\n\n```\nparallel-webpack -p=2\n```\n\n\n## Configurable configuration\n\nSometimes, you might want to access command line arguments within your `webpack.config.js`\nin order to create a more specific configuration.\n\n`parallel-webpack` will forward every parameter specified after `--` to the configuration\nas is:\n\n```\nparallel-webpack -- --app=trivago\n```\n\n\nWithin `webpack.config.js`:\n\n```\nconsole.log(process.argv);\n// =\u003e [ 'node', 'parallel-webpack', '--app=trivago' ]\n```\n\n`parallel-webpack` adds the first two values to `process.argv` to ensure that there\nare no differences between various ways of invoking the `webpack.config.js`.\n\n## Node.js API\n\nJust like webpack, you can also use `parallel-webpack` as an API from node.js\n(You can specify any other option used in [worker-farm](https://www.npmjs.com/package/worker-farm)):\n\n```javascript\nvar run = require('parallel-webpack').run,\n    configPath = require.resolve('./webpack.config.js');\n\nrun(configPath, {\n    watch: false,\n    maxRetries: 1,\n    stats: true, // defaults to false\n    maxConcurrentWorkers: 2 // use 2 workers\n});\n```\n\nYou can pass a notify callback as well.\n```javascript\nvar run = require('parallel-webpack').run,\n    configPath = require.resolve('./webpack.config.js'),\n    options = {/*...*/};\n\nfunction notify() {\n// do things\n}\n\nrun(configPath, options, notify);\n```\n**NOTE:** In watch mode notify callback provided with Node.js API will run **only once**\nwhen all of the builds are finished.\n\n### createVariants\n\n---\n\n#### createVariants(baseConfig: Object, variants: Object, configCallback: Function): Object[]\n\nAlters the given `baseConfig` with all possible `variants` and maps the result into\na valid webpack configuration using the given `configCallback`.\n\n#### createVariants(variants: Object, configCallback: Function): Object[]\n\nCreates all possible variations as specified in the `variants` object and\nmaps the result into a valid webpack configuration using the given `configCallback`.\n\n#### createVariants(baseConfig: Object, variants: Object): Object[]\n\nAlters the given `baseConfig` with all possible `variants` and returns it.\n\n#### createVariants(variants: Object): Object[]\n\nCreates all possible variations from the given `variants` and returns them as a flat array.\n","funding_links":[],"categories":["JavaScript","Build Tools"],"sub_categories":["React Components"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrivago%2Fparallel-webpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrivago%2Fparallel-webpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrivago%2Fparallel-webpack/lists"}