UNPKG

2.88 kBMarkdownView Raw
1# webpack-parallel-uglify-plugin [![Build Status](https://travis-ci.org/gdborton/webpack-parallel-uglify-plugin.svg?branch=master)](https://travis-ci.org/gdborton/webpack-parallel-uglify-plugin) [![Coverage Status](https://coveralls.io/repos/github/gdborton/webpack-parallel-uglify-plugin/badge.svg?branch=master)](https://coveralls.io/github/gdborton/webpack-parallel-uglify-plugin?branch=master)
2
3This plugin serves to help projects with many entry points speed up their builds. The UglifyJS plugin provided with webpack runs sequentially on each of the output files. This plugin runs uglify in parallel with one thread for each of your available cpus. This can lead to significantly reduced build times as minification is very CPU intensive.
4
5## Config
6
7Configuring is straightforward.
8
9```javascript
10import ParallelUglifyPlugin from 'webpack-parallel-uglify-plugin';
11
12module.exports = {
13 plugins: [
14 new ParallelUglifyPlugin({
15 // Optional regex, or array of regex to match file against. Only matching files get minified.
16 // Defaults to /.js$/, any file ending in .js.
17 test,
18 include, // Optional regex, or array of regex to include in minification. Only matching files get minified.
19 exclude, // Optional regex, or array of regex to exclude from minification. Matching files are not minified.
20 cacheDir, // Optional absolute path to use as a cache. If not provided, caching will not be used.
21 workerCount, // Optional int. Number of workers to run uglify. Defaults to num of cpus - 1 or asset count (whichever is smaller)
22 sourceMap, // Optional Boolean. This slows down the compilation. Defaults to false.
23 uglifyJS: {
24 // These pass straight through to uglify-js@3.
25 // Cannot be used with uglifyES.
26 // Defaults to {} if not neither uglifyJS or uglifyES are provided.
27 // You should use this option if you need to ensure es5 support. uglify-js will produce an error message
28 // if it comes across any es6 code that it can't parse.
29 },
30 uglifyES: {
31 // These pass straight through to uglify-es.
32 // Cannot be used with uglifyJS.
33 // uglify-es is a version of uglify that understands newer es6 syntax. You should use this option if the
34 // files that you're minifying do not need to run in older browsers/versions of node.
35 }
36 }),
37 ],
38};
39```
40
41### Example Timings
42
43These times were found by running webpack on a very large build, producing 493 output files and totaling 144.24 MiB before minifying. All times are listed with fully cached babel-loader for consistency.
44
45```
46No minification: Webpack build complete in: 86890ms (1m 26s)
47Built in uglify plugin: Webpack build complete in: 2543548ms (42m 23s)
48With parallel plugin: Webpack build complete in: 208671ms (3m 28s)
49With parallel/cache: Webpack build complete in: 98524ms (1m 38s)
50```