rollup-plugin-terser
Advanced tools
Comparing version 3.0.0 to 4.0.0
74
index.js
const { codeFrameColumns } = require("@babel/code-frame"); | ||
const Worker = require("jest-worker").default; | ||
const serialize = require("serialize-javascript"); | ||
const { generate } = require("escodegen"); | ||
const lave = require("lave"); | ||
@@ -10,35 +11,54 @@ function terser(userOptions = {}) { | ||
const minifierOptions = serialize( | ||
Object.assign({}, userOptions, { | ||
sourceMap: userOptions.sourcemap !== false, | ||
sourcemap: undefined, | ||
numWorkers: undefined | ||
}) | ||
); | ||
return { | ||
name: "terser", | ||
renderStart() { | ||
this.worker = new Worker(require.resolve("./transform.js"), { | ||
numWorkers: userOptions.numWorkers | ||
}); | ||
}, | ||
renderChunk(code, chunk, outputOptions) { | ||
if (!this.worker) { | ||
this.worker = new Worker(require.resolve("./transform.js"), { | ||
numWorkers: userOptions.numWorkers | ||
}); | ||
this.numOfBundles = 0; | ||
} | ||
renderChunk(code) { | ||
return this.worker.transform(code, minifierOptions).catch(error => { | ||
const { message, line, col: column } = error; | ||
console.error( | ||
codeFrameColumns(code, { start: { line, column } }, { message }) | ||
); | ||
throw error; | ||
this.numOfBundles++; | ||
const normalizedOptions = { | ||
...userOptions, | ||
sourceMap: userOptions.sourcemap !== false, | ||
module: outputOptions.format === "es" || outputOptions.format === "esm" | ||
}; | ||
for (let key of ["sourcemap", "numWorkers"]) { | ||
if (normalizedOptions.hasOwnProperty(key)) { | ||
delete normalizedOptions[key]; | ||
} | ||
} | ||
const serializedOptions = lave(normalizedOptions, { | ||
generate, | ||
format: "expression" | ||
}); | ||
}, | ||
generateBundle() { | ||
this.worker.end(); | ||
}, | ||
const result = this.worker | ||
.transform(code, serializedOptions) | ||
.catch(error => { | ||
const { message, line, col: column } = error; | ||
console.error( | ||
codeFrameColumns(code, { start: { line, column } }, { message }) | ||
); | ||
throw error; | ||
}); | ||
renderError() { | ||
this.worker.end(); | ||
const handler = () => { | ||
this.numOfBundles--; | ||
if (this.numOfBundles === 0) { | ||
this.worker.end(); | ||
this.worker = 0; | ||
} | ||
}; | ||
result.then(handler, handler); | ||
return result; | ||
} | ||
@@ -45,0 +65,0 @@ }; |
{ | ||
"name": "rollup-plugin-terser", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Rollup plugin to minify generated es bundle", | ||
@@ -28,18 +28,19 @@ "main": "index.js", | ||
"@babel/code-frame": "^7.0.0", | ||
"escodegen": "^1.11.0", | ||
"jest-worker": "^23.2.0", | ||
"serialize-javascript": "^1.5.0", | ||
"terser": "^3.8.2" | ||
"lave": "^1.1.10", | ||
"terser": "^3.14.0" | ||
}, | ||
"peerDependencies": { | ||
"rollup": ">=0.66.0 <1" | ||
"rollup": ">=0.66.0 <2" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.0.1", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.2.3", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^23.6.0", | ||
"jest": "^23.6.0", | ||
"prettier": "^1.14.2", | ||
"rollup": "^0.66.0" | ||
"prettier": "^1.15.3", | ||
"rollup": "^1.0.0" | ||
} | ||
} |
@@ -11,5 +11,7 @@ # rollup-plugin-terser [![Travis Build Status][travis-img]][travis] | ||
```sh | ||
npm i rollup-plugin-terser -D | ||
yarn add rollup-plugin-terser --dev | ||
``` | ||
*Note: this package requires rollup@0.66 and higher (including rollup@1.0.0)* | ||
## Usage | ||
@@ -22,3 +24,3 @@ | ||
rollup({ | ||
entry: "main.js", | ||
input: "main.js", | ||
plugins: [terser()] | ||
@@ -25,0 +27,0 @@ }); |
const { minify } = require("terser"); | ||
const transform = (code, optionsString) => { | ||
const options = eval(`(${optionsString})`) | ||
const options = eval(optionsString); | ||
const result = minify(code, options); | ||
@@ -6,0 +6,0 @@ if (result.error) { |
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
5824
65
80
6
+ Addedescodegen@^1.11.0
+ Addedlave@^1.1.10
+ Added@types/estree@1.0.6(transitive)
+ Addedacorn@7.4.1(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedlave@1.1.10(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedrollup@1.32.1(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
- Removedserialize-javascript@^1.5.0
- Removed@types/estree@0.0.39(transitive)
- Removedrollup@0.68.2(transitive)
- Removedserialize-javascript@1.9.1(transitive)
Updatedterser@^3.14.0