rollup-plugin-uglify
Advanced tools
Comparing version 4.0.0 to 5.0.0
39
index.js
const { codeFrameColumns } = require("@babel/code-frame"); | ||
const { minify } = require("uglify-js"); | ||
const Worker = require("jest-worker").default; | ||
function uglify(userOptions, minifier = minify) { | ||
const options = Object.assign({ sourceMap: true }, userOptions); | ||
function uglify(userOptions = {}) { | ||
if (userOptions.sourceMap != null) { | ||
throw Error("sourceMap option is removed, use sourcemap instead"); | ||
} | ||
const options = Object.assign({}, userOptions, { | ||
sourceMap: userOptions.sourcemap !== false | ||
}); | ||
return { | ||
name: "uglify", | ||
transformBundle(code) { | ||
const result = minifier(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; | ||
}); | ||
} | ||
@@ -21,0 +34,0 @@ }; |
{ | ||
"name": "rollup-plugin-uglify", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Rollup plugin to minify generated bundle", | ||
@@ -26,14 +26,18 @@ "main": "index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "^7.0.0-beta.47", | ||
"uglify-js": "^3.3.25" | ||
"@babel/code-frame": "^7.0.0", | ||
"jest-worker": "^23.2.0", | ||
"uglify-js": "^3.4.8" | ||
}, | ||
"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.4", | ||
"jest": "^22.4.4", | ||
"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,4 +6,9 @@ # rollup-plugin-uglify [![Travis Build Status][travis-img]][travis] | ||
[Rollup](https://github.com/rollup/rollup) plugin to minify generated bundle. | ||
[Rollup](https://github.com/rollup/rollup) plugin to minify generated bundle. Uses [UglifyJS](https://github.com/mishoo/UglifyJS2) under the hood. There are a few improvements over native uglify: | ||
* uglify is run in worker for every chunk | ||
* errors are displayed with [babel code frame](https://babeljs.io/docs/en/next/babel-code-frame.html) | ||
_Note: uglify-js is able to transpile only es5 syntax. If you want to transpile es6+ syntax use [terser](https://github.com/TrySound/rollup-plugin-terser) instead_ | ||
## Install | ||
@@ -18,10 +23,8 @@ | ||
```js | ||
import { rollup } from 'rollup'; | ||
import { uglify } from 'rollup-plugin-uglify'; | ||
import { rollup } from "rollup"; | ||
import { uglify } from "rollup-plugin-uglify"; | ||
rollup({ | ||
entry: 'main.js', | ||
plugins: [ | ||
uglify() | ||
] | ||
input: "main.js", | ||
plugins: [uglify()] | ||
}); | ||
@@ -33,8 +36,8 @@ ``` | ||
```js | ||
uglify(options, minifier) | ||
uglify(options); | ||
``` | ||
`options` – default: `{}`, type: `object`. [UglifyJS API options](https://github.com/mishoo/UglifyJS2/blob/master/README.md#minify-options) | ||
`options` - [uglifyJS API options](https://github.com/mishoo/UglifyJS2/blob/master/README.md#minify-options) | ||
`minifier` – default: `require('uglify-js').minify`, type: `function`. Module to use as a minifier. You can use other versions (or forks) of UglifyJS instead default one. | ||
`options.sourcemap` – default: `true`, type: `boolean`. The only own option which is used to generate source maps and pass them to rollup. | ||
@@ -51,8 +54,7 @@ ## Examples | ||
comments: function(node, comment) { | ||
var text = comment.value; | ||
var type = comment.type; | ||
if (type == "comment2") { | ||
// multiline comment | ||
return /@preserve|@license|@cc_on/i.test(text); | ||
} | ||
if (comment.type === "comment2") { | ||
// multiline comment | ||
return /@preserve|@license|@cc_on/i.test(comment.value); | ||
} | ||
return false; | ||
} | ||
@@ -68,3 +70,3 @@ } | ||
output: { | ||
comments: 'all' | ||
comments: "all" | ||
} | ||
@@ -71,0 +73,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
4917
31
76
4
+ Addedjest-worker@^23.2.0
+ Added@types/estree@0.0.39(transitive)
+ Added@types/node@22.7.0(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@6.19.8(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
Updated@babel/code-frame@^7.0.0
Updateduglify-js@^3.4.8