Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit f46a9cb

Browse files
committed
build: improve build config
1 parent 970a063 commit f46a9cb

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

.size-snapshot.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"lib/index.cjs.js": {
3-
"bundled": 5651,
4-
"minified": 3085,
5-
"gzipped": 1047
6-
},
72
"lib/index.esm.js": {
83
"bundled": 5360,
94
"minified": 2805,

rollup.config.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,62 @@
1-
import typescript from 'rollup-plugin-typescript2';
2-
import { terser } from 'rollup-plugin-terser';
31
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+
46
import pkg from './package.json';
57

8+
const getExternals = obj => [
9+
...Object.keys(obj.peerDependencies),
10+
...Object.keys(obj.dependencies),
11+
];
12+
613
const createConfig = ({ plugins, ...restConfig } = {}) => ({
714
input: 'src/index.ts',
8-
external: [...Object.keys(pkg.peerDependencies), ...Object.keys(pkg.dependencies)],
15+
external: getExternals(pkg),
916
plugins: [
17+
replace({
18+
'process.env.NODE_ENV': JSON.stringify('production'),
19+
}),
1020
typescript({
1121
tsconfig: './tsconfig.json',
1222
typescript: require('typescript'),
23+
rollupCommonJSResolveHack: true,
24+
clean: true,
1325
}),
1426
...plugins,
1527
],
1628
...restConfig,
1729
});
1830

31+
const createOutput = ({ ...config }) => ({
32+
exports: 'named',
33+
sourcemap: true,
34+
...config,
35+
});
36+
1937
export default [
2038
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+
}),
2643
plugins: [sizeSnapshot(), terser()],
2744
}),
2845
createConfig({
2946
experimentalCodeSplitting: true,
3047
optimizeChunks: true,
3148
input: [
49+
'./src/index.ts',
3250
'./src/components/List/List.tsx',
3351
'./src/components/Show/Show.tsx',
3452
'./src/components/ShowIfElse/ShowIfElse.tsx',
3553
'./src/components/Switch/Switch.tsx',
3654
'./src/hocs/Hideable/Hideable.tsx',
3755
],
38-
output: {
56+
output: createOutput({
3957
dir: 'lib',
4058
format: 'cjs',
41-
},
59+
}),
4260
plugins: [terser()],
4361
}),
4462
];

0 commit comments

Comments
 (0)