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

Commit

Permalink
feat(uglify): add missing toplevel, nameCache, keep_classnames,…
Browse files Browse the repository at this point in the history
… `keep_fnames` and `safari10` options (`uglifyOptions`) (#229)
  • Loading branch information
evilebottnawi authored and michael-ciniawsky committed Feb 15, 2018
1 parent 88cde68 commit 990de2a
Show file tree
Hide file tree
Showing 4 changed files with 696 additions and 14 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,28 @@ Number of concurrent runs.

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`ie8`**|`{Boolean}`|`false`|Enable IE8 Support|
|**`ecma`**|`{Number}`|`undefined`|Supported ECMAScript Version (`5`, `6`, `7` or `8`). Affects `parse`, `compress` && `output` options|
|**`warnings`**|`{Boolean}`|`false`|Display Warnings|
|**[`parse`](https://github.com/mishoo/UglifyJS2/tree/harmony#parse-options)**|`{Object}`|`{}`|Additional Parse Options|
|**[`compress`](https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options)**|`{Boolean\|Object}`|`true`|Additional Compress Options|
|**[`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 ⚠️)|
|**[`output`](https://github.com/mishoo/UglifyJS2/tree/harmony#output-options)**|`{Object}`|`{}`|Additional Output Options (The defaults are optimized for best compression)|
|**[`compress`](https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options)**|`{Boolean\|Object}`|`true`|Additional Compress Options|
|**`warnings`**|`{Boolean}`|`false`|Display Warnings|
|**`toplevel`**|`{Boolean}`|`false`|Enable top level variable and function name mangling and to drop unused variables and functions|
|**`nameCache`**|`{Object}`|`null`|Enable cache of mangled variable and property names across multiple invocations|
|**`ie8`**|`{Boolean}`|`false`|Enable IE8 Support|
|**`keep_classnames`**|`{Boolean}`|`undefined`|Enable prevent discarding or mangling of class names|
|**`keep_fnames`**|`{Boolean}`|`false`| Enable prevent discarding or mangling of function names. Useful for code relying on `Function.prototype.name`. If the top level minify option `keep_classnames` is `undefined` it will be overriden with the value of the top level minify option `keep_fnames`|
|**`safari10`**|`{Boolean}`|`false`|Enable work around Safari 10/11 bugs in loop scoping and `await`|

**webpack.config.js**
```js
[
new UglifyJsPlugin({
uglifyOptions: {
ie8: false,
ecma: 8,
warnings: false,
parse: {...options},
compress: {...options},
mangle: {
...options,
properties: {
Expand All @@ -187,8 +193,12 @@ Number of concurrent runs.
beautify: false,
...options
},
compress: {...options},
warnings: false
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false,
}
})
]
Expand Down
24 changes: 16 additions & 8 deletions src/uglify/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
import uglify from 'uglify-es';

const buildUglifyOptions = ({
ie8,
ecma,
warnings,
parse = {},
compress = {},
mangle,
output,
compress = {},
warnings,
toplevel,
nameCache,
} = {}) => ({
ie8,
/* eslint-disable camelcase */
keep_classnames,
keep_fnames,
/* eslint-enable camelcase */
safari10,
} = {}) => ({
ecma,
warnings,
parse,
compress,
mangle: mangle == null ? true : mangle,
output: {
shebang: true,
Expand All @@ -25,12 +31,14 @@ const buildUglifyOptions = ({
semicolons: true,
...output,
},
compress,
warnings,
toplevel,
nameCache,
// Ignoring sourcemap from options
sourceMap: null,
toplevel,
nameCache,
ie8,
keep_classnames,
keep_fnames,
safari10,
});

const buildComments = (options, uglifyOptions, extractedComments) => {
Expand Down
Loading

0 comments on commit 990de2a

Please sign in to comment.