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

feat(uglify): add missing toplevel, nameCache, keep_classnames, keep_fnames and safari10 options (uglifyOptions) #229

Merged
merged 1 commit into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**[warnings](#warnings)**

(if there is a link, otherwise ignore)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No link

|**[`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