rollup-plugin-terser
Advanced tools
Comparing version 5.1.3 to 5.2.0
57
index.js
const { codeFrameColumns } = require("@babel/code-frame"); | ||
const Worker = require("jest-worker").default; | ||
const serialize = require("serialize-javascript"); | ||
const { createFilter } = require('rollup-pluginutils'); | ||
const { createFilter } = require("rollup-pluginutils"); | ||
@@ -11,3 +11,5 @@ function terser(userOptions = {}) { | ||
const filter = createFilter( userOptions.include, userOptions.exclude, { resolve: false } ); | ||
const filter = createFilter(userOptions.include, userOptions.exclude, { | ||
resolve: false | ||
}); | ||
@@ -18,3 +20,3 @@ return { | ||
renderChunk(code, chunk, outputOptions) { | ||
if(!filter(chunk.fileName)){ | ||
if (!filter(chunk.fileName)) { | ||
return null; | ||
@@ -32,8 +34,16 @@ } | ||
// TODO rewrite with object spread after node6 drop | ||
const normalizedOptions = Object.assign({}, userOptions, { | ||
sourceMap: userOptions.sourcemap !== false, | ||
module: outputOptions.format === "es" || outputOptions.format === "esm" | ||
}); | ||
const defaultOptions = { | ||
sourceMap: userOptions.sourcemap !== false | ||
}; | ||
if (outputOptions.format === "es" || outputOptions.format === "esm") { | ||
defaultOptions.module = true; | ||
} | ||
if (outputOptions.format === "cjs") { | ||
defaultOptions.toplevel = true; | ||
} | ||
// TODO rewrite with object spread after dropping node v6 | ||
const normalizedOptions = Object.assign({}, defaultOptions, userOptions); | ||
// remove plugin specific options | ||
for (let key of ["include", "exclude", "sourcemap", "numWorkers"]) { | ||
@@ -68,3 +78,32 @@ if (normalizedOptions.hasOwnProperty(key)) { | ||
return result; | ||
return result.then(result => { | ||
if (result.nameCache) { | ||
let { vars, props } = userOptions.nameCache; | ||
// only assign nameCache.vars if it was provided, and if terser produced values: | ||
if (vars) { | ||
const newVars = | ||
result.nameCache.vars && result.nameCache.vars.props; | ||
if (newVars) { | ||
vars.props = vars.props || {}; | ||
Object.assign(vars.props, newVars); | ||
} | ||
} | ||
// support populating an empty nameCache object: | ||
if (!props) { | ||
props = userOptions.nameCache.props = {}; | ||
} | ||
// merge updated props into original nameCache object: | ||
const newProps = | ||
result.nameCache.props && result.nameCache.props.props; | ||
if (newProps) { | ||
props.props = props.props || {}; | ||
Object.assign(props.props, newProps); | ||
} | ||
} | ||
return result.result; | ||
}); | ||
} | ||
@@ -71,0 +110,0 @@ }; |
{ | ||
"name": "rollup-plugin-terser", | ||
"version": "5.1.3", | ||
"version": "5.2.0", | ||
"description": "Rollup plugin to minify generated es bundle", | ||
@@ -34,7 +34,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "^7.0.0", | ||
"jest-worker": "^24.6.0", | ||
"rollup-pluginutils": "^2.8.1", | ||
"@babel/code-frame": "^7.5.5", | ||
"jest-worker": "^24.9.0", | ||
"rollup-pluginutils": "^2.8.2", | ||
"serialize-javascript": "^2.1.2", | ||
"terser": "^4.1.0" | ||
"terser": "^4.6.2" | ||
}, | ||
@@ -45,9 +45,9 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.5.0", | ||
"@babel/plugin-transform-async-to-generator": "^7.5.0", | ||
"babel-jest": "^24.8.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.18.2", | ||
"rollup": "^1.16.6" | ||
"@babel/core": "^7.7.7", | ||
"@babel/plugin-transform-async-to-generator": "^7.7.4", | ||
"babel-jest": "^24.9.0", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.1", | ||
"rollup": "^1.29.0" | ||
} | ||
} |
@@ -58,2 +58,7 @@ # rollup-plugin-terser [![Travis Build Status][travis-img]][travis] | ||
Note: some terser options are set by the plugin automatically: | ||
* `module: true` is set when `format` is `esm` or `es` | ||
* `toplevel: true` is set when `format` is `cjs` | ||
Specifically include/exclude chunk files names (minimatch pattern, or array of minimatch patterns), By default all chunk files will be minify. | ||
@@ -60,0 +65,0 @@ |
@@ -9,3 +9,3 @@ const { minify } = require("terser"); | ||
} else { | ||
return result; | ||
return { result, nameCache: options.nameCache }; | ||
} | ||
@@ -12,0 +12,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9579
120
125
Updated@babel/code-frame@^7.5.5
Updatedjest-worker@^24.9.0
Updatedrollup-pluginutils@^2.8.2
Updatedterser@^4.6.2