Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit e12337f

Browse files
docs(README): standardize
1 parent ee16639 commit e12337f

File tree

1 file changed

+185
-95
lines changed

1 file changed

+185
-95
lines changed

README.md

Lines changed: 185 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,236 @@
11
[![npm][npm]][npm-url]
2+
[![node][node]][node-url]
23
[![deps][deps]][deps-url]
34
[![test][test]][test-url]
45
[![coverage][cover]][cover-url]
5-
[![quality][quality]][quality-url]
66
[![chat][chat]][chat-url]
77

8+
89
<div align="center">
9-
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
1010
<a href="https://github.com/webpack/webpack">
11-
<img width="200" height="200" vspace="" hspace="25"
11+
<img width="200" height="200"
1212
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
1313
</a>
1414
<h1>UglifyJS Webpack Plugin</h1>
15-
<p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/v2.x">UglifyJS v2</a> to minify your JavaScript.<p>
15+
<p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/harmony">UglifyJS v3</a> to minify your JavaScript<p>
1616
</div>
1717

18-
> Note that webpack contains the same plugin under `webpack.optimize.UglifyJsPlugin`. This is a standalone version for those that want to control the version of UglifyJS. The documentation is valid apart from the installation instructions in that case.
18+
> ℹ️ webpack contains the same plugin under `webpack.optimize.UglifyJsPlugin`. The documentation is valid apart from the installation instructions
1919
2020
<h2 align="center">Install</h2>
2121

22-
With [Yarn](https://yarnpkg.com):
23-
24-
```bash
25-
yarn add uglifyjs-webpack-plugin --dev
26-
```
27-
28-
With npm:
29-
3022
```bash
31-
npm install uglifyjs-webpack-plugin --save-dev
23+
npm i -D uglifyjs-webpack-plugin
3224
```
3325

3426
<h2 align="center">Usage</h2>
3527

36-
```javascript
37-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
28+
**webpack.config.js**
29+
```js
30+
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
3831

3932
module.exports = {
40-
entry: {...},
41-
output: {...},
42-
module: {...},
4333
plugins: [
44-
new UglifyJsPlugin()
34+
new UglifyJSPlugin()
4535
]
46-
};
36+
}
4737
```
4838

4939
<h2 align="center">Options</h2>
5040

51-
This plugin supports UglifyJS features as discussed below:
52-
53-
| Property | Type | Default | Description |
54-
| --- | --- | --- | --- |
55-
| compress | boolean, object | true | See [UglifyJS documentation](http://lisperator.net/uglifyjs/compress). |
56-
| mangle | boolean, object | true | See below. |
57-
| beautify | boolean | false | Beautify output. |
58-
| output | An object providing options for UglifyJS [OutputStream](https://github.com/mishoo/UglifyJS2/blob/v2.x/lib/output.js) | | Lower level access to UglifyJS output. |
59-
| comments | boolean, RegExp, function(astNode, comment) -> boolean | Defaults to preserving comments containing `/*!`, `/**!`, `@preserve` or `@license`. | Comment related configuration. |
60-
| extractComments | boolean, RegExp, function (astNode, comment) -> boolean, object | false | Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a), since webpack 2.3.0) |
61-
| sourceMap | boolean | false | Use SourceMaps to map error message locations to modules. This slows down the compilation. **Important!** `cheap` source map options don't work with the plugin! |
62-
| test | RegExp, Array<RegExp> | <code>/\.js($&#124;\?)/i</code> | Test to match files against. |
63-
| include | RegExp, Array<RegExp> | | Test only `include` files. |
64-
| exclude | RegExp, Array<RegExp> | | Files to `exclude` from testing. |
65-
| warningsFilter | function(source) -> boolean | | Allow to filter uglify warnings (since webpack 2.3.0) |
66-
| parallel | boolean, object | false | Use multi-process parallel running and file cache to improve the build speed. |
67-
68-
<h2 align="center">Mangling</h2>
69-
70-
`mangle (boolean|object)` - Passing `true` or an object enables and provides options for UglifyJS name mangling. See [UglifyJS documentation](https://github.com/mishoo/UglifyJS2/tree/v2.x#mangle) for mangle options. Example configuration, this will **not** mangle properties (see below):
71-
72-
```javascript
73-
new UglifyJsPlugin({
74-
mangle: {
75-
// Skip mangling these
76-
except: ['$super', '$', 'exports', 'require']
77-
}
78-
})
41+
|Name|Type|Default|Description|
42+
|:--:|:--:|:-----:|:----------|
43+
|**`test`**|`{RegExp\|Array<RegExp>}`| <code>/\.js($&#124;\?)/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+
|**`parallel`**|`{Boolean\|Object}`|`false`|Use multi-process parallel running and file cache to improve the build speed|
47+
|**`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**|
48+
|**`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)|
49+
|**`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`)|
50+
|**`warningsFilter`**|`{Function(source) -> {Boolean}}`|``|Allow to filter uglify warnings|
51+
52+
### `test`
53+
54+
**webpack.config.js**
55+
```js
56+
[
57+
new UglifyJSPlugin({
58+
test: /\.js($&#124;\?)/i
59+
})
60+
]
61+
```
62+
63+
### `include`
64+
65+
**webpack.config.js**
66+
```js
67+
[
68+
new UglifyJSPlugin({
69+
include: /\/includes/
70+
})
71+
]
7972
```
8073

81-
`mangle.props (boolean|object)` - Passing `true` or an object enables and provides options for UglifyJS property mangling - see [UglifyJS documentation](https://github.com/mishoo/UglifyJS2/tree/v2.x#mangleproperties-options) for mangleProperties options.
74+
### `exclude`
75+
76+
**webpack.config.js**
77+
```js
78+
[
79+
new UglifyJSPlugin({
80+
exclude: /\/excludes/
81+
})
82+
]
83+
```
8284

83-
> Note: the UglifyJS docs warn that [you will probably break your source if you use property mangling](https://github.com/mishoo/UglifyJS2/tree/v2.x#mangling-property-names---mangle-props), so if you aren’t sure why you’d need this feature, you most likely shouldn’t be using it! This is **not** enabled by default.
85+
### `parallel`
8486

85-
Example configuration, this will mangle both names and properties:
87+
**webpack.config.js**
88+
```js
89+
[
90+
new UglifyJSPlugin({
91+
parallel: true
92+
})
93+
]
94+
```
8695

87-
```javascript
88-
new UglifyJsPlugin({
89-
mangle: {
90-
props: true
91-
}
92-
})
96+
|Name|Type|Default|Description|
97+
|:--:|:--:|:-----:|:----------|
98+
|**`cache`**|`{Boolean}`|`node_modules/.cache/uglifyjs-webpack-plugin`|Enable file caching|
99+
|**`workers`**|`{Boolean\|Object}`|`os.cpus().length - 1`|Number of concurrent runs, default is the `maximum`|
100+
101+
**webpack.config.js**
102+
```js
103+
[
104+
new UglifyJSPlugin({
105+
parallel: {
106+
cache: true
107+
workers: 2 // for e.g
108+
}
109+
})
110+
]
93111
```
94112

95-
<h2 align="center">Extracting Comments</h2>
113+
> ℹ️ Parallelization can speedup your build significantly and is therefore **highly recommended**
96114
97-
The `extractComments` option can be
98-
- `true`: All 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`
99-
- regular expression (given as `RegExp` or `string`) or a `function (astNode, comment) -> boolean`:
100-
All 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.
101-
- an `object` consisting of the following keys, all optional:
102-
- `condition`: regular expression or function (see previous point)
103-
- `filename`: The file where the extracted comments will be stored. Can be either a `string` or `function (string) -> string` which will be given the original filename. Default is to append the suffix `.LICENSE` to the original filename.
104-
- `banner`: The banner text that points to the extracted file and will be added on top of the original file. will be added to 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.
105-
Default: `/*! For license information please see foo.js.LICENSE */`
115+
### `sourceMap`
116+
117+
**webpack.config.js**
118+
```js
119+
[
120+
new UglifyJSPlugin({
121+
sourceMap: true
122+
})
123+
]
124+
```
125+
126+
> ⚠️ **`cheap-source-map` options don't work with this plugin**
127+
128+
### [`uglifyOptions`](https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options)
129+
130+
|Name|Type|Default|Description|
131+
|:--:|:--:|:-----:|:----------|
132+
|**`ie8`**|`{Boolean}`|`false`|Enable IE8 Support|
133+
|**`ecma`**|`{Number}`|`undefined`|Supported ECMAScript Version (`5`, `6`, `7` or `8`). Affects `parse`, `compress` && `output` options|
134+
|**[`parse`](https://github.com/mishoo/UglifyJS2/tree/harmony#parse-options)**|`{Object}`|`{}`|Additional Parse Options|
135+
|**[`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 ⚠️)|
136+
|**[`output`](https://github.com/mishoo/UglifyJS2/tree/harmony#output-options)**|`{Object}`|`{}`|Additional Output Options (The defaults are optimized for best compression)|
137+
|**[`compress`](https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options)**|`{Boolean\|Object}`|`true`|Additional Compress Options|
138+
|**`warnings`**|`{Boolean}`|`false`|Display Warnings|
139+
140+
**webpack.config.js**
141+
```js
142+
[
143+
new UglifyJSPlugin({
144+
uglifyOptions: {
145+
ie8: false,
146+
ecma: 8,
147+
parse: {...options},
148+
mangle: {
149+
...options,
150+
properties: {
151+
// mangle property options
152+
}
153+
},
154+
output: {
155+
comments: false,
156+
beautify: false,
157+
...options
158+
},
159+
compress: {...options},
160+
warnings: false
161+
}
162+
})
163+
]
164+
```
106165

107-
<h2 align="center">Run in parallel</h2>
166+
### `extractComments`
108167

109-
The `parallel` option can be
168+
**`{Boolean}`**
110169

111-
- `true`: Enable multi-process parallel running with file cache
112-
- an `object` consisting of the following keys, all optional:
113-
- `workers`: The maximum number of concurrent runs. If it is `true`, it is equal to `require('os').cpus().length - 1`.
114-
- `cache`: Enable file caching. If it is `true`, it is equal to `"node_modules/.cache/uglifyjs-webpack-plugin"`.
170+
All 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`
171+
172+
**`{RegExp|String}` or `{Function<(node, comment) -> {Boolean}>}`**
173+
174+
All 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.
175+
176+
**`{Object}`**
177+
178+
|Name|Type|Default|Description|
179+
|:--:|:--:|:-----:|:----------|
180+
|**`condition`**|`{Regex\|Function}`|``|Regular Expression or function (see previous point)|
181+
|**`filename`**|`{String\|Function}`|`compilation.assets[file]`|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|
182+
|**`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|
183+
184+
### `warningsFilter`
185+
186+
**webpack.config.js**
187+
```js
188+
[
189+
new UglifyJsPlugin({
190+
warningsFilter: (src) => true
191+
})
192+
]
193+
```
115194

116195
<h2 align="center">Maintainers</h2>
117196

118197
<table>
119198
<tbody>
120199
<tr>
121200
<td align="center">
122-
<img width="150" height="150"
123-
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
124-
</br>
125-
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
201+
<a href="https://github.com/hulkish">
202+
<img width="150" height="150" src="https://github.com/hulkish.png?size=150">
203+
</br>
204+
Steven Hargrove
205+
</a>
126206
</td>
127207
<td align="center">
128-
<img width="150" height="150"
129-
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
130-
</br>
131-
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
208+
<a href="https://github.com/bebraw">
209+
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
210+
</br>
211+
Juho Vepsäläinen
212+
</a>
132213
</td>
133214
<td align="center">
134-
<img width="150" height="150"
135-
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
136-
</br>
137-
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
215+
<a href="https://github.com/d3viant0ne">
216+
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
217+
</br>
218+
Joshua Wiens
219+
</a>
138220
</td>
139221
<td align="center">
140-
<img width="150" height="150"
141-
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
142-
</br>
143-
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
222+
<a href="https://github.com/michael-ciniawsky">
223+
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
224+
</br>
225+
Michael Ciniawsky
226+
</a>
227+
</td>
228+
<td align="center">
229+
<a href="https://github.com/evilebottnawi">
230+
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
231+
</br>
232+
Alexander Krasnoyarov
233+
</a>
144234
</td>
145235
</tr>
146236
<tbody>
@@ -150,17 +240,17 @@ The `parallel` option can be
150240
[npm]: https://img.shields.io/npm/v/uglifyjs-webpack-plugin.svg
151241
[npm-url]: https://npmjs.com/package/uglifyjs-webpack-plugin
152242

243+
[node]: https://img.shields.io/node/v/uglifyjs-webpack-plugin.svg
244+
[node-url]: https://nodejs.org
245+
153246
[deps]: https://david-dm.org/webpack-contrib/uglifyjs-webpack-plugin.svg
154247
[deps-url]: https://david-dm.org/webpack-contrib/uglifyjs-webpack-plugin
155248

156-
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
157-
[chat-url]: https://gitter.im/webpack/webpack
158-
159249
[test]: https://secure.travis-ci.org/webpack-contrib/uglifyjs-webpack-plugin.svg
160250
[test-url]: http://travis-ci.org/webpack-contrib/uglifyjs-webpack-plugin
161251

162252
[cover]: https://codecov.io/gh/webpack-contrib/uglifyjs-webpack-plugin/branch/master/graph/badge.svg
163253
[cover-url]: https://codecov.io/gh/webpack-contrib/uglifyjs-webpack-plugin
164254

165-
[quality]: https://www.bithound.io/github/webpack-contrib/uglifyjs-webpack-plugin/badges/score.svg
166-
[quality-url]: https://www.bithound.io/github/webpack-contrib/uglifyjs-webpack-plugin
255+
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
256+
[chat-url]: https://gitter.im/webpack/webpack

0 commit comments

Comments
 (0)