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

Commit a5a539c

Browse files
squash: init options example
1 parent aeb474e commit a5a539c

File tree

1 file changed

+117
-27
lines changed

1 file changed

+117
-27
lines changed

README.md

Lines changed: 117 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
[![coverage][cover]][cover-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">
1111
<img width="200" height="200"
1212
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
@@ -15,27 +15,26 @@
1515
<p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/v2.x">UglifyJS v2</a> to minify your JavaScript.<p>
1616
</div>
1717

18+
1819
> ℹ️ 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.
1920
2021
<h2 align="center">Install</h2>
2122

2223
```bash
23-
npm install uglifyjs-webpack-plugin --save-dev
24-
yarn add uglifyjs-webpack-plugin --dev
24+
npm i -D uglifyjs-webpack-plugin
2525
```
2626

27-
> ⚠️ The plugin has a peer dependency to uglify-es (UglifyJS), so in order to use the plugin, also uglify-js has to be installed.
27+
> ⚠️ The plugin has a peer dependency to `uglify-es` (UglifyJS), so in order to use the plugin, also `uglify-es` has to be installed.
2828
2929
```bash
30-
npm install uglify-es --save-dev
31-
yarn add uglify-es --dev
30+
npm i -D uglify-es
3231
```
3332

3433
<h2 align="center">Usage</h2>
3534

3635
**webpack.config.js**
3736
```js
38-
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
37+
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
3938

4039
module.exports = {
4140
plugins: [
@@ -46,48 +45,104 @@ module.exports = {
4645

4746
<h2 align="center">Options</h2>
4847

49-
This plugin supports UglifyJS features as discussed below:
50-
5148
|Name|Type|Default|Description|
5249
|:--:|:--:|:-----:|:----------|
53-
|**`compress`**|`{Boolean\|Object}`|`true`|See [UglifyJS documentation](http://lisperator.net/uglifyjs/compress)|
50+
|**`test`**|`{RegExp\|Array<RegExp>}`| <code>/\.js($&#124;\?)/i</code>|Test to match files against|
51+
|**`output`**|`{Object}`|`{}`|An object providing options for UglifyJS [OutputStream](https://github.com/mishoo/UglifyJS2/blob/v2.x/lib/output.js) (Lower level access to `Uglifyjs` output)|
5452
|**`mangle`**|`{Boolean\|Object}`|`true`|See [below](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/readme#mangle)|
53+
|**`compress`**|`{Boolean\|Object}`|`true`|See [UglifyJS documentation](http://lisperator.net/uglifyjs/compress)|
5554
|**`beautify`**|`{Boolean}`|`false`|Beautify output|
56-
|**`output`**|`{Object}`|`{}`|An object providing options for UglifyJS [OutputStream](https://github.com/mishoo/UglifyJS2/blob/v2.x/lib/output.js) (Lower level access to `Uglifyjs` output)|
57-
|**`comments`**|`{Boolean\|RegExp\|Function<(node, comment) -> {Boolean}>}`| Defaults to preserving comments containing `/*!`, `/**!`, `@preserve` or `@license`. |Comment related configuration|
55+
|**`comments`**|`{Boolean\|RegExp\|`false`|Function<(node, comment) -> {Boolean}>}`| Defaults to preserving comments containing `/*!`, `/**!`, `@preserve` or `@license`|
5856
|**`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), since webpack 2.3.0)|
59-
|**`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 the plugin!**|
60-
|**`test`**|`{RegExp\|Array<RegExp>}`| <code>/\.js($&#124;\?)/i</code> |Test to match files against|
57+
|**`warningsFilter`**|`{Function(source) -> {Boolean}}`|``|Allow to filter uglify warnings (since webpack 2.3.0)|
6158
|**`include`**|`{RegExp\|Array<RegExp>}`|`undefined`|Test only `include` files|
6259
|**`exclude`**|`{RegExp\|Array<RegExp>}`|`undefined`|Files to `exclude` from testing|
63-
|**`warningsFilter`**|{`Function(source) -> {Boolean}}`|``|Allow to filter uglify warnings (since webpack 2.3.0)|
60+
|**`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 the plugin!**|
6461

62+
### `test`
63+
64+
**webpack.config.js**
65+
```js
66+
[
67+
new UglifyJSPlugin({ test: /\.js($&#124;\?)/i })
68+
]
69+
```
70+
71+
### `output`
72+
73+
**webpack.config.js**
74+
```js
75+
[
76+
new UglifyJSPlugin({ output: {...options} })
77+
]
78+
```
6579

6680
### `mangle`
6781

6882
`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):
6983

84+
**webpack.config.js**
7085
```js
71-
new UglifyJsPlugin({
72-
mangle: {
73-
// Skip mangling these
74-
except: ['$super', '$', 'exports', 'require']
75-
}
76-
})
86+
[
87+
new UglifyJsPlugin({
88+
mangle: {
89+
// Skip mangling these
90+
except: ['$super', '$', 'exports', 'require']
91+
}
92+
})
93+
]
7794
```
7895

7996
`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.
8097

8198
> ℹ️ 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.
8299
83-
Example configuration, this will mangle both names and properties:
100+
**webpack.config.js**
101+
```js
102+
[
103+
new UglifyJsPlugin({
104+
mangle: {
105+
props: true
106+
}
107+
})
108+
]
109+
```
110+
111+
### `compress`
84112

113+
**webpack.config.js**
114+
```js
115+
[
116+
new UglifyJSPlugin({ compress: true || {...options} })
117+
]
118+
```
119+
120+
### `beautify`
121+
122+
**webpack.config.js**
85123
```js
86-
new UglifyJsPlugin({
87-
mangle: {
88-
props: true
89-
}
90-
})
124+
[
125+
new UglifyJSPlugin({ beautify: true })
126+
]
127+
```
128+
129+
### `comments`
130+
131+
**webpack.config.js**
132+
```js
133+
[
134+
new UglifyJSPlugin({ comments: true })
135+
]
136+
```
137+
```js
138+
[
139+
new UglifyJSPlugin({ comments: /@license/ })
140+
]
141+
```
142+
```js
143+
[
144+
new UglifyJSPlugin({ comments: (node, comment) => true })
145+
]
91146
```
92147

93148
### `extractComments`
@@ -102,6 +157,41 @@ The `extractComments` option can be
102157
- `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.
103158
Default: `/*! For license information please see foo.js.LICENSE */`
104159

160+
### `warningsFilter`
161+
162+
**webpack.config.js**
163+
```js
164+
[
165+
new UglifyJSPlugin({ warningsFilter: (src) => true })
166+
]
167+
```
168+
169+
### `include`
170+
171+
**webpack.config.js**
172+
```js
173+
[
174+
new UglifyJSPlugin({ include: /\/includes/ })
175+
]
176+
```
177+
178+
### `exclude`
179+
180+
**webpack.config.js**
181+
```js
182+
[
183+
new UglifyJSPlugin({ exclude: /\/excludes/ })
184+
]
185+
```
186+
187+
### `sourceMap`
188+
189+
**webpack.config.js**
190+
```js
191+
[
192+
new UglifyJSPlugin({ sourceMap: true })
193+
]
194+
```
105195

106196
<h2 align="center">Maintainers</h2>
107197

0 commit comments

Comments
 (0)