rollup-plugin-terser
Advanced tools
Comparing version 1.0.1 to 2.0.0
38
index.js
const { codeFrameColumns } = require("@babel/code-frame"); | ||
const { minify } = require("terser"); | ||
const Worker = require("jest-worker").default; | ||
function terser(userOptions) { | ||
const options = Object.assign({ sourceMap: true }, userOptions); | ||
function terser(userOptions = {}) { | ||
if (userOptions.sourceMap != null) { | ||
throw Error("sourceMap option is removed, use sourcemap instead"); | ||
} | ||
const options = Object.assign({}, userOptions, { | ||
sourceMap: userOptions.sourcemap !== false | ||
}); | ||
@@ -10,12 +15,19 @@ return { | ||
transformBundle(code) { | ||
const result = minify(code, options); | ||
if (result.error) { | ||
const { message, line, col: column } = result.error; | ||
console.error( | ||
codeFrameColumns(code, { start: { line, column } }, { message }) | ||
); | ||
throw result.error; | ||
} | ||
return result; | ||
renderChunk(code) { | ||
const worker = new Worker(require.resolve("./transform.js")); | ||
return worker | ||
.transform(code, options) | ||
.then(result => { | ||
worker.end(); | ||
return result; | ||
}) | ||
.catch(error => { | ||
worker.end(); | ||
const { message, line, col: column } = error; | ||
console.error( | ||
codeFrameColumns(code, { start: { line, column } }, { message }) | ||
); | ||
throw error; | ||
}); | ||
} | ||
@@ -22,0 +34,0 @@ }; |
{ | ||
"name": "rollup-plugin-terser", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Rollup plugin to minify generated es bundle", | ||
@@ -26,14 +26,18 @@ "main": "index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "^7.0.0-beta.47", | ||
"terser": "^3.7.5" | ||
"@babel/code-frame": "^7.0.0", | ||
"jest-worker": "^23.2.0", | ||
"terser": "^3.8.2" | ||
}, | ||
"peerDependencies": { | ||
"rollup": ">=0.65.0 <1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0-beta.47", | ||
"@babel/preset-env": "^7.0.0-beta.47", | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^22.4.3", | ||
"jest": "^22.4.3", | ||
"prettier": "^1.12.1", | ||
"rollup": "^0.59.1" | ||
"babel-jest": "^23.4.2", | ||
"jest": "^23.5.0", | ||
"prettier": "^1.14.2", | ||
"rollup": "^0.65.0" | ||
} | ||
} |
@@ -6,3 +6,3 @@ # rollup-plugin-terser [![Travis Build Status][travis-img]][travis] | ||
[Rollup](https://github.com/rollup/rollup) plugin to minify generated es bundle. | ||
[Rollup](https://github.com/rollup/rollup) plugin to minify generated es bundle. Uses [terser](https://github.com/fabiosantoscode/terser) under the hood. | ||
@@ -33,4 +33,6 @@ ## Install | ||
`options` – default: `{}`, type: `object`. [Terser API options](https://github.com/fabiosantoscode/terser#minify-options) | ||
`options` - [terser API options](https://github.com/fabiosantoscode/terser#minify-options) | ||
`options.sourcemap` - default: `true`, type: `boolean`. The only own option which is used to generate source maps and pass them to rollup. | ||
## Examples | ||
@@ -37,0 +39,0 @@ |
4558
31
72
4
+ Addedjest-worker@^23.2.0
+ Added@types/estree@0.0.39(transitive)
+ Added@types/node@20.14.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjest-worker@23.2.0(transitive)
+ Addedmerge-stream@1.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrollup@0.68.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedundici-types@5.26.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
Updated@babel/code-frame@^7.0.0
Updatedterser@^3.8.2