From 3b88029be1a89125eded8fff5a72563891bc8352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=A9ng=20Nguy=E1=BB=85n?= Date: Tue, 5 Feb 2019 20:48:01 +0700 Subject: [PATCH] support minify umd format --- package.json | 4 +++- rollup.config.js | 55 ++++++++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 0dc092b..a18edf1 100644 --- a/package.json +++ b/package.json @@ -50,12 +50,14 @@ "rimraf": "^2.6.2", "rollup": "^1.1.2", "rollup-plugin-babel": "^4.3.2", + "rollup-plugin-terser": "^4.0.4", "sinon": "^4.0.2" }, "scripts": { "prebuild": "rimraf dist/*", - "start": "react-scripts start", "build": "rollup --config", + "postbuild": "BUILD_MINIFY=true rollup --config", + "start": "react-scripts start", "test": "react-scripts test --env=jsdom", "coverage": "npm test -- --coverage", "eject": "react-scripts eject", diff --git a/rollup.config.js b/rollup.config.js index b95f9a4..35dabbc 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,28 +1,43 @@ import babel from 'rollup-plugin-babel'; +import { terser } from 'rollup-plugin-terser'; + +const isMinify = process.env.BUILD_MINIFY ? true : false; + +let output = [ + { + file: 'dist/react-paginating.cjs.js', + name: 'react-paginating-cjs', + format: 'cjs' + }, + { + file: 'dist/react-paginating.esm.js', + name: 'react-paginating-esm', + format: 'esm' + }, + { + file: 'dist/react-paginating.umd.js', + name: 'react-paginating-umd', + format: 'umd', + sourcemap: true + }, +]; + +if (isMinify) { + output = { + file: 'dist/react-paginating.umd.min.js', + name: 'react-paginating.umd.min', + format: 'iife', + sourcemap: true + }; +} export default [{ input: 'src/Pagination/index.js', - output: [ - { - file: 'dist/react-paginating.cjs.js', - name: 'react-paginating-cjs', - format: 'cjs' - }, - { - file: 'dist/react-paginating.umd.js', - name: 'react-paginating-umd', - format: 'umd', - sourcemap: true - }, - { - file: 'dist/react-paginating.esm.js', - name: 'react-paginating-esm', - format: 'esm' - } - ], + output, plugins: [ babel({ exclude: 'node_modules/**' - }) - ] + }), + isMinify ? terser() : null + ] }]; \ No newline at end of file