Socket
Socket
Sign inDemoInstall

rollup-plugin-uglify

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-uglify - npm Package Compare versions

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 @@ });

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