UNPKG

9.04 kBMarkdownView Raw
1[![npm][npm]][npm-url]
2[![node][node]][node-url]
3[![deps][deps]][deps-url]
4[![test][test]][test-url]
5[![coverage][cover]][cover-url]
6[![chat][chat]][chat-url]
7
8
9<div align="center">
10 <a href="https://github.com/webpack/webpack">
11 <img width="200" height="200"
12 src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
13 </a>
14 <h1>UglifyJS Webpack Plugin</h1>
15 <p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/harmony">UglifyJS v3 </a><a href="https://npmjs.com/package/uglify-es">(`uglify-es`)</a> to minify your JavaScript</p>
16</div>
17
18> ℹ️ `webpack =< v3.0.0` currently contains [`v0.4.6`](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/version-0.4) of this plugin under `webpack.optimize.UglifyJsPlugin` as an alias. For usage of the latest version (`v1.0.0`), please follow the instructions below. Aliasing `v1.0.0` as `webpack.optimize.UglifyJsPlugin` is scheduled for `webpack v4.0.0`
19
20<h2 align="center">Install</h2>
21
22```bash
23npm i -D uglifyjs-webpack-plugin
24```
25
26<h2 align="center">Usage</h2>
27
28**webpack.config.js**
29```js
30const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
31
32module.exports = {
33 plugins: [
34 new UglifyJsPlugin()
35 ]
36}
37```
38
39<h2 align="center">Options</h2>
40
41|Name|Type|Default|Description|
42|:--:|:--:|:-----:|:----------|
43|**`test`**|`{RegExp\|Array<RegExp>}`| <code>/\\.js$/i</code>|Test to match files against|
44|**`include`**|`{RegExp\|Array<RegExp>}`|`undefined`|Files to `include`|
45|**`exclude`**|`{RegExp\|Array<RegExp>}`|`undefined`|Files to `exclude`|
46|**`cache`**|`{Boolean\|String}`|`false`|Enable file caching|
47|**`parallel`**|`{Boolean\|Number}`|`false`|Use multi-process parallel running to improve the build speed|
48|**`sourceMap`**|`{Boolean}`|`false`|Use source maps to map error message locations to modules (This slows down the compilation) ⚠️ **`cheap-source-map` options don't work with this plugin**|
49|**`uglifyOptions`**|`{Object}`|[`{...defaults}`](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/master#uglifyoptions)|`uglify` [Options](https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options)|
50|**`extractComments`**|`{Boolean\|RegExp\|Function<(node, comment) -> {Boolean\|Object}>}`|`false`|Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a) (`webpack >= 2.3.0`)|
51|**`warningsFilter`**|`{Function(source) -> {Boolean}}`|`() => true`|Allow to filter uglify warnings|
52
53### `test`
54
55**webpack.config.js**
56```js
57[
58 new UglifyJsPlugin({
59 test: /\.js($|\?)/i
60 })
61]
62```
63
64### `include`
65
66**webpack.config.js**
67```js
68[
69 new UglifyJsPlugin({
70 include: /\/includes/
71 })
72]
73```
74
75### `exclude`
76
77**webpack.config.js**
78```js
79[
80 new UglifyJsPlugin({
81 exclude: /\/excludes/
82 })
83]
84```
85
86### `cache`
87
88#### `{Boolean}`
89
90**webpack.config.js**
91```js
92[
93 new UglifyJsPlugin({
94 cache: true
95 })
96]
97```
98
99Enable file caching.
100Default path to cache directory: `node_modules/.cache/uglifyjs-webpack-plugin`.
101
102#### `{String}`
103
104**webpack.config.js**
105```js
106[
107 new UglifyJsPlugin({
108 cache: 'path/to/cache'
109 })
110]
111```
112
113Path to cache directory.
114
115### `parallel`
116
117#### `{Boolean}`
118
119**webpack.config.js**
120```js
121[
122 new UglifyJsPlugin({
123 parallel: true
124 })
125]
126```
127
128Enable parallelization.
129Default number of concurrent runs: `os.cpus().length - 1`.
130
131#### `{Number}`
132
133**webpack.config.js**
134```js
135[
136 new UglifyJsPlugin({
137 parallel: 4
138 })
139]
140```
141
142Number of concurrent runs.
143
144> ℹ️ Parallelization can speedup your build significantly and is therefore **highly recommended**
145
146### `sourceMap`
147
148**webpack.config.js**
149```js
150[
151 new UglifyJsPlugin({
152 sourceMap: true
153 })
154]
155```
156
157> ⚠️ **`cheap-source-map` options don't work with this plugin**
158
159### [`uglifyOptions`](https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options)
160
161|Name|Type|Default|Description|
162|:--:|:--:|:-----:|:----------|
163|**`ie8`**|`{Boolean}`|`false`|Enable IE8 Support|
164|**`ecma`**|`{Number}`|`undefined`|Supported ECMAScript Version (`5`, `6`, `7` or `8`). Affects `parse`, `compress` && `output` options|
165|**[`parse`](https://github.com/mishoo/UglifyJS2/tree/harmony#parse-options)**|`{Object}`|`{}`|Additional Parse Options|
166|**[`mangle`](https://github.com/mishoo/UglifyJS2/tree/harmony#mangle-options)**|`{Boolean\|Object}`|`true`|Enable Name Mangling (See [Mangle Properties](https://github.com/mishoo/UglifyJS2/tree/harmony#mangle-properties-options) for advanced setups, use with ⚠️)|
167|**[`output`](https://github.com/mishoo/UglifyJS2/tree/harmony#output-options)**|`{Object}`|`{}`|Additional Output Options (The defaults are optimized for best compression)|
168|**[`compress`](https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options)**|`{Boolean\|Object}`|`true`|Additional Compress Options|
169|**`warnings`**|`{Boolean}`|`false`|Display Warnings|
170
171**webpack.config.js**
172```js
173[
174 new UglifyJsPlugin({
175 uglifyOptions: {
176 ie8: false,
177 ecma: 8,
178 parse: {...options},
179 mangle: {
180 ...options,
181 properties: {
182 // mangle property options
183 }
184 },
185 output: {
186 comments: false,
187 beautify: false,
188 ...options
189 },
190 compress: {...options},
191 warnings: false
192 }
193 })
194]
195```
196
197### `extractComments`
198
199#### `{Boolean}`
200
201All comments that normally would be preserved by the `comments` option will be moved to a separate file. If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE`.
202
203#### `{RegExp|String}` or `{Function<(node, comment) -> {Boolean}>}`
204
205All comments that match the given expression (resp. are evaluated to `true` by the function) will be extracted to the separate file. The `comments` option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted.
206
207#### `{Object}`
208
209|Name|Type|Default|Description|
210|:--:|:--:|:-----:|:----------|
211|**`condition`**|`{Regex\|Function}`|``|Regular Expression or function (see previous point)|
212|**`filename`**|`{String\|Function}`|`${file}.LICENSE`|The file where the extracted comments will be stored. Can be either a `{String}` or a `{Function<(string) -> {String}>}`, which will be given the original filename. Default is to append the suffix `.LICENSE` to the original filename|
213|**`banner`**|`{Boolean\|String\|Function}`|`/*! For license information please see ${filename}.js.LICENSE */`|The banner text that points to the extracted file and will be added on top of the original file. Can be `false` (no banner), a `{String}`, or a `{Function<(string) -> {String}` that will be called with the filename where extracted comments have been stored. Will be wrapped into comment|
214
215### `warningsFilter`
216
217**webpack.config.js**
218```js
219[
220 new UglifyJsPlugin({
221 warningsFilter: (src) => true
222 })
223]
224```
225
226<h2 align="center">Maintainers</h2>
227
228<table>
229 <tbody>
230 <tr>
231 <td align="center">
232 <a href="https://github.com/hulkish">
233 <img width="150" height="150" src="https://github.com/hulkish.png?size=150">
234 </br>
235 Steven Hargrove
236 </a>
237 </td>
238 <td align="center">
239 <a href="https://github.com/bebraw">
240 <img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
241 </br>
242 Juho Vepsäläinen
243 </a>
244 </td>
245 <td align="center">
246 <a href="https://github.com/d3viant0ne">
247 <img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
248 </br>
249 Joshua Wiens
250 </a>
251 </td>
252 <td align="center">
253 <a href="https://github.com/michael-ciniawsky">
254 <img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
255 </br>
256 Michael Ciniawsky
257 </a>
258 </td>
259 <td align="center">
260 <a href="https://github.com/evilebottnawi">
261 <img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
262 </br>
263 Alexander Krasnoyarov
264 </a>
265 </td>
266 </tr>
267 <tbody>
268</table>
269
270
271[npm]: https://img.shields.io/npm/v/uglifyjs-webpack-plugin.svg
272[npm-url]: https://npmjs.com/package/uglifyjs-webpack-plugin
273
274[node]: https://img.shields.io/node/v/uglifyjs-webpack-plugin.svg
275[node-url]: https://nodejs.org
276
277[deps]: https://david-dm.org/webpack-contrib/uglifyjs-webpack-plugin.svg
278[deps-url]: https://david-dm.org/webpack-contrib/uglifyjs-webpack-plugin
279
280[test]: https://secure.travis-ci.org/webpack-contrib/uglifyjs-webpack-plugin.svg
281[test-url]: http://travis-ci.org/webpack-contrib/uglifyjs-webpack-plugin
282
283[cover]: https://codecov.io/gh/webpack-contrib/uglifyjs-webpack-plugin/branch/master/graph/badge.svg
284[cover-url]: https://codecov.io/gh/webpack-contrib/uglifyjs-webpack-plugin
285
286[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
287[chat-url]: https://gitter.im/webpack/webpack