-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
50 lines (45 loc) · 1.28 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import tsConfigJson from './tsconfig.json' assert { type: 'json' };
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
const name = 'ReactDomLazyloadComponent';
const input = 'src/index.tsx';
const outputFormats = ['cjs', 'es'];
const buildTsConfig = ({ sourceMap }) => {
const extraConfig = { compilerOptions: { sourceMap } };
return typescript({ ...tsConfigJson, ...extraConfig });
};
const productionConfigs = outputFormats.map(format => ({
input,
output: [
{
file: format === 'es' ? 'dist/index.js' : `dist/${format}/index.js`,
format,
sourcemap: tsConfigJson.compilerOptions.sourceMap,
name,
compact: true,
},
],
plugins: [
peerDepsExternal(),
buildTsConfig({
sourceMap: tsConfigJson.compilerOptions.sourceMap,
}),
terser(),
],
}));
const developmentConfigs = outputFormats.map(format => ({
input,
output: [
{
file:
format === 'es'
? 'dist/index.development.js'
: `dist/${format}/index.development.js`,
format,
name,
},
],
plugins: [peerDepsExternal(), buildTsConfig({ sourceMap: false })],
}));
export default [...productionConfigs, ...developmentConfigs];