|
1 | | -import typescript from 'rollup-plugin-typescript2'; |
2 | | -import { terser } from 'rollup-plugin-terser'; |
3 | 1 | import { sizeSnapshot } from 'rollup-plugin-size-snapshot'; |
| 2 | +import { terser } from 'rollup-plugin-terser'; |
| 3 | +import replace from 'rollup-plugin-replace'; |
| 4 | +import typescript from 'rollup-plugin-typescript2'; |
| 5 | + |
4 | 6 | import pkg from './package.json'; |
5 | 7 |
|
| 8 | +const getExternals = obj => [ |
| 9 | + ...Object.keys(obj.peerDependencies), |
| 10 | + ...Object.keys(obj.dependencies), |
| 11 | +]; |
| 12 | + |
6 | 13 | const createConfig = ({ plugins, ...restConfig } = {}) => ({ |
7 | 14 | input: 'src/index.ts', |
8 | | - external: [...Object.keys(pkg.peerDependencies), ...Object.keys(pkg.dependencies)], |
| 15 | + external: getExternals(pkg), |
9 | 16 | plugins: [ |
| 17 | + replace({ |
| 18 | + 'process.env.NODE_ENV': JSON.stringify('production'), |
| 19 | + }), |
10 | 20 | typescript({ |
11 | 21 | tsconfig: './tsconfig.json', |
12 | 22 | typescript: require('typescript'), |
| 23 | + rollupCommonJSResolveHack: true, |
| 24 | + clean: true, |
13 | 25 | }), |
14 | 26 | ...plugins, |
15 | 27 | ], |
16 | 28 | ...restConfig, |
17 | 29 | }); |
18 | 30 |
|
| 31 | +const createOutput = ({ ...config }) => ({ |
| 32 | + exports: 'named', |
| 33 | + sourcemap: true, |
| 34 | + ...config, |
| 35 | +}); |
| 36 | + |
19 | 37 | export default [ |
20 | 38 | createConfig({ |
21 | | - output: { file: `lib/${pkg.main}`, format: 'cjs' }, |
22 | | - plugins: [sizeSnapshot(), terser()], |
23 | | - }), |
24 | | - createConfig({ |
25 | | - output: { file: `lib/${pkg.module}`, format: 'esm' }, |
| 39 | + output: createOutput({ |
| 40 | + file: `lib/${pkg.module}`, |
| 41 | + format: 'esm', |
| 42 | + }), |
26 | 43 | plugins: [sizeSnapshot(), terser()], |
27 | 44 | }), |
28 | 45 | createConfig({ |
29 | 46 | experimentalCodeSplitting: true, |
30 | 47 | optimizeChunks: true, |
31 | 48 | input: [ |
| 49 | + './src/index.ts', |
32 | 50 | './src/components/List/List.tsx', |
33 | 51 | './src/components/Show/Show.tsx', |
34 | 52 | './src/components/ShowIfElse/ShowIfElse.tsx', |
35 | 53 | './src/components/Switch/Switch.tsx', |
36 | 54 | './src/hocs/Hideable/Hideable.tsx', |
37 | 55 | ], |
38 | | - output: { |
| 56 | + output: createOutput({ |
39 | 57 | dir: 'lib', |
40 | 58 | format: 'cjs', |
41 | | - }, |
| 59 | + }), |
42 | 60 | plugins: [terser()], |
43 | 61 | }), |
44 | 62 | ]; |
0 commit comments