Skip to content

Commit

Permalink
Rename sourceMap into sourcemap according rollup api
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Aug 30, 2018
1 parent ab6f418 commit f72cc35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
20 changes: 9 additions & 11 deletions README.md
Expand Up @@ -16,26 +16,24 @@ npm i rollup-plugin-uglify -D
## Usage

```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()
]
entry: "main.js",
plugins: [uglify()]
});
```

## Options

```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.

## Examples

Expand All @@ -46,7 +44,7 @@ If you'd like to preserve comments (for licensing for example), then you can spe
```js
uglify({
output: {
comments: function (node, comment) {
comments: function(node, comment) {
if (comment.type === "comment2") {
// multiline comment
return /@preserve|@license|@cc_on/i.test(comment.value);
Expand All @@ -62,7 +60,7 @@ Alternatively, you can also choose to keep all comments (e.g. if a licensing hea
```js
uglify({
output: {
comments: 'all'
comments: "all"
}
});
```
Expand Down
10 changes: 8 additions & 2 deletions index.js
@@ -1,8 +1,14 @@
const { codeFrameColumns } = require("@babel/code-frame");
const Worker = require("jest-worker").default;

function uglify(userOptions) {
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",
Expand Down
12 changes: 12 additions & 0 deletions test/test.js
Expand Up @@ -37,6 +37,18 @@ test("minify with sourcemaps", async () => {
expect(result.map).toBeTruthy();
});

test("does not allow to pass sourceMap", async () => {
try {
const bundle = await rollup({
input: "test/fixtures/sourcemap.js",
plugins: [uglify({ sourceMap: false })]
});
expect(true).toBeFalsy();
} catch (error) {
expect(error.toString()).toMatch(/sourceMap option is removed/);
}
});

test("throw error on uglify fail", async () => {
try {
const bundle = await rollup({
Expand Down

0 comments on commit f72cc35

Please sign in to comment.