From 2c93b36c1f0c2832b2d4f61e6ba218ef119b3be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 11 Aug 2020 17:17:47 +0800 Subject: [PATCH] 1.0.0 --- .gitignore | 17 +++++++++++++++++ LICENSE | 21 +++++++++++++++++++++ Readme.md | 2 ++ index.es.js | 24 ++++++++++++++++++++++++ index.js | 26 ++++++++++++++++++++++++++ package.json | 16 ++++++++++++++++ 6 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Readme.md create mode 100644 index.es.js create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8f1f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ + +.vscode +node_modules/ +dist/ + +*.sublime-project +*.sublime-workspace +package-lock.json + + +._* + +.Spotlight-V100 +.Trashes +.DS_Store +.AppleDouble +.LSOverride \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ab60297 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..ae95808 --- /dev/null +++ b/Readme.md @@ -0,0 +1,2 @@ +## @rollup/plugin-uglify +> Rollup plugin to minify generated bundle, base on terser. Support ES6+. \ No newline at end of file diff --git a/index.es.js b/index.es.js new file mode 100644 index 0000000..499e42b --- /dev/null +++ b/index.es.js @@ -0,0 +1,24 @@ +/** + * rollup plugin + * @author yutent + * @date 2020/08/11 15:46:57 + */ + +import { minify } from 'terser' + +export default function uglify(options = {}) { + // force sourcemap creation + var opt = Object.assign({ sourceMap: true }, options) + + return { + name: 'uglify', + renderChunk(code) { + var result = minify(code, opt) + if (result.error) { + console.error(result.error) + throw result.error + } + return result + } + } +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..eab4269 --- /dev/null +++ b/index.js @@ -0,0 +1,26 @@ +/** + * rollup plugin + * @author yutent + * @date 2020/08/11 15:46:57 + */ + +var minify = require('terser').minify + +function uglify(options = {}) { + // force sourcemap creation + var opt = Object.assign({ sourceMap: true }, options) + + return { + name: 'uglify', + renderChunk(code) { + var result = minify(code, opt) + if (result.error) { + console.error(result.error) + throw result.error + } + return result + } + } +} + +module.exports = uglify diff --git a/package.json b/package.json new file mode 100644 index 0000000..41481fe --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "@bytedo/rollup-plugin-uglify", + "version": "1.0.0", + "description": "Rollup plugin to minify generated bundle, base on terser. Support ES6+.", + "main": "index.js", + "module": "index.es.js", + "author": "yutent", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/bytedo/rollup-plugin-uglify.git" + }, + "dependencies": { + "terser": "^5.0.0" + } +}