Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rollup-plugin-terser

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-terser - npm Package Compare versions

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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc