You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 5, 2019. It is now read-only.
<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>
16
16
</div>
17
17
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
19
19
20
20
<h2align="center">Install</h2>
21
21
22
-
With [Yarn](https://yarnpkg.com):
23
-
24
22
```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.
| 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($|\?)/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. |
`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
-
newUglifyJsPlugin({
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($|\?)/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**|
|**`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
+
newUglifyJSPlugin({
57
+
test:/\.js($|\?)/i
58
+
})
59
+
]
92
60
```
93
61
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`
95
63
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
+
newUglifyJSPlugin({
68
+
include:/\/includes/
69
+
})
70
+
]
71
+
```
97
72
98
-
Example configuration, this will mangle both names and properties:
73
+
### `exclude`
99
74
100
-
```javascript
101
-
newUglifyJsPlugin({
102
-
mangle: {
103
-
props:true
104
-
}
105
-
})
75
+
**webpack.config.js**
76
+
```js
77
+
[
78
+
newUglifyJSPlugin({
79
+
exclude:/\/excludes/
80
+
})
81
+
]
106
82
```
107
83
108
-
<h2align="center">Extracting Comments</h2>
84
+
### `sourceMap`
85
+
86
+
**webpack.config.js**
87
+
```js
88
+
[
89
+
newUglifyJSPlugin({
90
+
sourceMap:true
91
+
})
92
+
]
93
+
```
94
+
95
+
> ⚠️ **`cheap-source-map` options don't work with this plugin**
|**[`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)|
-`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`
112
138
- regular expression (given as `RegExp` or `string`) or a `function (astNode, comment) -> boolean`:
113
139
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.
114
140
- an `object` consisting of the following keys, all optional:
115
141
-`condition`: regular expression or function (see previous point)
116
142
-`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.
117
143
-`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
+
118
145
Default: `/*! For license information please see foo.js.LICENSE */`
0 commit comments