rollup-plugin-terser
Advanced tools
+47
-27
| 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 @@ }; |
+9
-8
| { | ||
| "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" | ||
| } | ||
| } |
+4
-2
@@ -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 @@ }); |
+1
-1
| 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) { |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
5824
12.85%65
30%80
2.56%6
20%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated