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

Commit 9268e30

Browse files
docs(README): standardize
1 parent cfa6c53 commit 9268e30

File tree

1 file changed

+140
-92
lines changed

1 file changed

+140
-92
lines changed

README.md

Lines changed: 140 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,199 @@
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/master">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-
2422
```bash
25-
yarn add uglifyjs-webpack-plugin --dev
26-
```
27-
28-
With npm:
29-
30-
```bash
31-
npm install uglifyjs-webpack-plugin --save-dev
32-
```
33-
34-
**Important!** The plugin has a peer dependency to uglify-js, so in order to use the plugin, also uglify-js has to be installed. The currently (2017/1/25) available uglify-js npm packages; however, do not support minification of ES6 code. In order to support ES6, an ES6-capable, a.k.a. _harmony_, version of UglifyJS has to be provided.
35-
36-
If your minification target is ES6:
37-
38-
```bash
39-
yarn add git://github.com/mishoo/UglifyJS2#harmony-v2.8.22 --dev
40-
```
41-
42-
If your minification target is ES5:
43-
44-
```bash
45-
yarn add uglify-js --dev
23+
npm i -D uglifyjs-webpack-plugin
4624
```
4725

4826
<h2 align="center">Usage</h2>
4927

50-
```javascript
51-
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
28+
**webpack.config.js**
29+
```js
30+
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
5231

5332
module.exports = {
54-
entry: {...},
55-
output: {...},
56-
module: {...},
5733
plugins: [
5834
new UglifyJSPlugin()
5935
]
60-
};
36+
}
6137
```
6238

6339
<h2 align="center">Options</h2>
6440

65-
This plugin supports UglifyJS features as discussed below:
66-
67-
| Property | Type | Default | Description |
68-
| --- | --- | --- | --- |
69-
| compress | boolean, object | true | See [UglifyJS documentation](http://lisperator.net/uglifyjs/compress). |
70-
| mangle | boolean, object | true | See below. |
71-
| beautify | boolean | false | Beautify output. |
72-
| 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. |
73-
| comments | boolean, RegExp, function(astNode, comment) -> boolean | Defaults to preserving comments containing `/*!`, `/**!`, `@preserve` or `@license`. | Comment related configuration. |
74-
| 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) |
75-
| 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! |
76-
| test | RegExp, Array<RegExp> | <code>/\.js($&#124;\?)/i</code> | Test to match files against. |
77-
| include | RegExp, Array<RegExp> | | Test only `include` files. |
78-
| exclude | RegExp, Array<RegExp> | | Files to `exclude` from testing. |
79-
| warningsFilter | function(source) -> boolean | | Allow to filter uglify warnings (since webpack 2.3.0) |
80-
81-
<h2 align="center">Mangling</h2>
82-
83-
`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):
84-
85-
```javascript
86-
new UglifyJsPlugin({
87-
mangle: {
88-
// Skip mangling these
89-
except: ['$super', '$', 'exports', 'require']
90-
}
91-
})
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+
|**`sourceMap`**|`{Boolean}`|`false`|Use SourceMaps to map error message locations to modules (This slows down the compilation) ⚠️ **`cheap-source-map` options don't work with this plugin**|
47+
|**`uglifyOptions`**|`{Object}`|[`{}`](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/readme#uglifyoptions)|`uglify` [Options](https://github.com/mishoo/UglifyJS2/tree/master#minify-options)|
48+
|**`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`)|
49+
|**`warningsFilter`**|`{Function(source) -> {Boolean}}`|``|Allow to filter uglify warnings|
50+
51+
### `test`
52+
53+
**webpack.config.js**
54+
```js
55+
[
56+
new UglifyJSPlugin({
57+
test: /\.js($&#124;\?)/i
58+
})
59+
]
9260
```
9361

94-
`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.
62+
### `include`
9563

96-
> 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.
64+
**webpack.config.js**
65+
```js
66+
[
67+
new UglifyJSPlugin({
68+
include: /\/includes/
69+
})
70+
]
71+
```
9772

98-
Example configuration, this will mangle both names and properties:
73+
### `exclude`
9974

100-
```javascript
101-
new UglifyJsPlugin({
102-
mangle: {
103-
props: true
104-
}
105-
})
75+
**webpack.config.js**
76+
```js
77+
[
78+
new UglifyJSPlugin({
79+
exclude: /\/excludes/
80+
})
81+
]
10682
```
10783

108-
<h2 align="center">Extracting Comments</h2>
84+
### `sourceMap`
85+
86+
**webpack.config.js**
87+
```js
88+
[
89+
new UglifyJSPlugin({
90+
sourceMap: true
91+
})
92+
]
93+
```
94+
95+
> ⚠️ **`cheap-source-map` options don't work with this plugin**
96+
97+
### [`uglifyOptions`](https://github.com/mishoo/UglifyJS2/tree/master#minify-options)
98+
99+
|Name|Type|Default|Description|
100+
|:--:|:--:|:-----:|:----------|
101+
|**`ie8`**|`{Boolean}`|`false`|Enable IE8 Support|
102+
|**[`parse`](https://github.com/mishoo/UglifyJS2/tree/master#parse-options)**|`{Object}`|`{}`|Additional Parse Options|
103+
|**[`mangle`](https://github.com/mishoo/UglifyJS2/tree/master#mangle-options)**|`{Boolean\|Object}`|`true`|Enable Name Mangling (See [Mangle Properties](https://github.com/mishoo/UglifyJS2/tree/master#mangle-properties-options) for advanced setups, use with ⚠️)|
104+
|**[`output`](https://github.com/mishoo/UglifyJS2/tree/master#output-options)**|`{Object}`|`{}`|Additional Output Options (The defaults are optimized for best compression)|
105+
|**[`compress`](https://github.com/mishoo/UglifyJS2/tree/master#compress-options)**|`{Boolean\|Object}`|`true`|Additional Compress Options|
106+
|**`warnings`**|`{Boolean}`|`false`|Display Warnings|
107+
108+
**webpack.config.js**
109+
```js
110+
[
111+
new UglifyJSPlugin({
112+
uglifyOptions: {
113+
ie8: false,
114+
parse: {...options},
115+
mangle: {
116+
...options,
117+
properties: {
118+
// mangle property options
119+
}
120+
},
121+
output: {
122+
comments: false,
123+
beautify: false,
124+
...options
125+
},
126+
compress: {...options},
127+
warnings: false
128+
}
129+
})
130+
]
131+
```
132+
133+
### `extractComments`
109134

110135
The `extractComments` option can be
136+
111137
- `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`
112138
- regular expression (given as `RegExp` or `string`) or a `function (astNode, comment) -> boolean`:
113139
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.
114140
- an `object` consisting of the following keys, all optional:
115141
- `condition`: regular expression or function (see previous point)
116142
- `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.
117143
- `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.
144+
118145
Default: `/*! For license information please see foo.js.LICENSE */`
119146

147+
### `warningsFilter`
148+
149+
**webpack.config.js**
150+
```js
151+
[
152+
new UglifyJSPlugin({
153+
warningsFilter: (src) => true
154+
})
155+
]
156+
```
120157

121158
<h2 align="center">Maintainers</h2>
122159

123160
<table>
124161
<tbody>
125162
<tr>
126163
<td align="center">
127-
<img width="150" height="150"
128-
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
129-
</br>
130-
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
164+
<a href="https://github.com/TheLarkInn">
165+
<img width="150" height="150" src="https://github.com/TheLarkInn.png?size=150">
166+
</br>
167+
Sean Larkin
168+
</a>
131169
</td>
132170
<td align="center">
133-
<img width="150" height="150"
134-
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
135-
</br>
136-
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
171+
<a href="https://github.com/bebraw">
172+
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
173+
</br>
174+
Juho Vepsäläinen
175+
</a>
137176
</td>
138177
<td align="center">
139-
<img width="150" height="150"
140-
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
141-
</br>
142-
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
178+
<a href="https://github.com/d3viant0ne">
179+
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
180+
</br>
181+
Joshua Wiens
182+
</a>
143183
</td>
144184
<td align="center">
145-
<img width="150" height="150"
146-
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
147-
</br>
148-
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
185+
<a href="https://github.com/michael-ciniawsky">
186+
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
187+
</br>
188+
Michael Ciniawsky
189+
</a>
190+
</td>
191+
<td align="center">
192+
<a href="https://github.com/evilebottnawi">
193+
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
194+
</br>
195+
Alexander Krasnoyarov
196+
</a>
149197
</td>
150198
</tr>
151199
<tbody>
@@ -155,17 +203,17 @@ Default: `/*! For license information please see foo.js.LICENSE */`
155203
[npm]: https://img.shields.io/npm/v/uglifyjs-webpack-plugin.svg
156204
[npm-url]: https://npmjs.com/package/uglifyjs-webpack-plugin
157205

206+
[node]: https://img.shields.io/node/v/uglifyjs-webpack-plugin.svg
207+
[node-url]: https://nodejs.org
208+
158209
[deps]: https://david-dm.org/webpack-contrib/uglifyjs-webpack-plugin.svg
159210
[deps-url]: https://david-dm.org/webpack-contrib/uglifyjs-webpack-plugin
160211

161-
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
162-
[chat-url]: https://gitter.im/webpack/webpack
163-
164212
[test]: https://secure.travis-ci.org/webpack-contrib/uglifyjs-webpack-plugin.svg
165213
[test-url]: http://travis-ci.org/webpack-contrib/uglifyjs-webpack-plugin
166214

167215
[cover]: https://codecov.io/gh/webpack-contrib/uglifyjs-webpack-plugin/branch/master/graph/badge.svg
168216
[cover-url]: https://codecov.io/gh/webpack-contrib/uglifyjs-webpack-plugin
169217

170-
[quality]: https://www.bithound.io/github/webpack-contrib/uglifyjs-webpack-plugin/badges/score.svg
171-
[quality-url]: https://www.bithound.io/github/webpack-contrib/uglifyjs-webpack-plugin
218+
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
219+
[chat-url]: https://gitter.im/webpack/webpack

0 commit comments

Comments
 (0)