|
1 | 1 | import babel from "rollup-plugin-babel";
|
2 | 2 | import commonjs from "rollup-plugin-commonjs";
|
3 |
| -import external from "rollup-plugin-peer-deps-external"; |
4 | 3 | import postcss from "rollup-plugin-postcss";
|
5 | 4 | import resolve from "rollup-plugin-node-resolve";
|
6 | 5 | import { terser } from "rollup-plugin-terser";
|
| 6 | +import { uglify } from "rollup-plugin-uglify"; |
7 | 7 |
|
8 | 8 | import packageJSON from "./package.json";
|
9 | 9 |
|
| 10 | +const input = "./src/index.js"; |
| 11 | +const external = [ |
| 12 | + // ensure peer dependencies are declared as externals |
| 13 | + ...Object.keys(packageJSON.peerDependencies), |
| 14 | + // same for actual dependencies, to allow for dependency resolution/de-duplication by consumers |
| 15 | + ...Object.keys(packageJSON.dependencies) |
| 16 | +]; |
| 17 | +const postcssOptions = { |
| 18 | + extract: false, |
| 19 | + extensions: [".scss"], |
| 20 | + minimize: true |
| 21 | +}; |
| 22 | +const babelOptions = { |
| 23 | + exclude: "node_modules/**" |
| 24 | +}; |
| 25 | + |
10 | 26 | export default [
|
| 27 | + // CommonJS |
11 | 28 | {
|
12 |
| - input: "./src/index.js", |
| 29 | + input, |
13 | 30 | output: {
|
14 | 31 | file: packageJSON.main,
|
| 32 | + format: "cjs" |
| 33 | + }, |
| 34 | + external, |
| 35 | + plugins: [ |
| 36 | + // collect styles from SCSS, minimise them and include them in the JS module (i.e. not as separate .css file) |
| 37 | + postcss(postcssOptions), |
| 38 | + // transpile for compatibility |
| 39 | + babel(babelOptions), |
| 40 | + // resolve dependencies that are ES modules |
| 41 | + resolve(), |
| 42 | + // resolve dependencies that are (legacy) CommonJS modules |
| 43 | + commonjs(), |
| 44 | + // minify to reduce size |
| 45 | + uglify() |
| 46 | + ] |
| 47 | + }, |
| 48 | + // ES Module |
| 49 | + { |
| 50 | + input, |
| 51 | + output: { |
| 52 | + file: packageJSON.module, |
15 | 53 | format: "es",
|
16 | 54 | exports: "named"
|
17 | 55 | },
|
| 56 | + external, |
18 | 57 | plugins: [
|
19 |
| - // ensure peer dependencies are declared as externals |
20 |
| - external(), |
21 | 58 | // collect styles from SCSS, minimise them and include them in the JS module (i.e. not as separate .css file)
|
22 |
| - postcss({ |
23 |
| - extract: false, |
24 |
| - extensions: [".scss"], |
25 |
| - minimize: true |
26 |
| - }), |
| 59 | + postcss(postcssOptions), |
27 | 60 | // transpile for compatibility
|
28 |
| - babel({ |
29 |
| - exclude: "node_modules/**" |
30 |
| - }), |
| 61 | + babel(babelOptions), |
31 | 62 | // resolve dependencies that are ES modules
|
32 | 63 | resolve(),
|
33 | 64 | // resolve dependencies that are (legacy) CommonJS modules
|
|
0 commit comments