From f72cc35865fc8a6f8556d1027ebdc4c5c53f0ada Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Thu, 30 Aug 2018 21:11:53 +0300 Subject: [PATCH] Rename sourceMap into sourcemap according rollup api --- README.md | 20 +++++++++----------- index.js | 10 ++++++++-- test/test.js | 12 ++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3663ba9..3a97bdd 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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); @@ -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" } }); ``` diff --git a/index.js b/index.js index 61c6f0c..f0ae44a 100644 --- a/index.js +++ b/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", diff --git a/test/test.js b/test/test.js index c2d9b91..111610a 100644 --- a/test/test.js +++ b/test/test.js @@ -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({