-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.ts
104 lines (95 loc) · 2.67 KB
/
rollup.config.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// SPDX-License-Identifier: MIT
import pluginCommonJS from '@rollup/plugin-commonjs';
import pluginDts from 'rollup-plugin-dts';
import pluginHTML from '@rollup/plugin-html';
import pluginJSON from '@rollup/plugin-json';
import pluginReplace from '@rollup/plugin-replace';
import pluginTerser from '@rollup/plugin-terser';
import pluginTypeScript from '@rollup/plugin-typescript';
import { nodeResolve as pluginNodeResolve } from '@rollup/plugin-node-resolve';
import type { RollupOptions, ModuleFormat } from 'rollup';
const SRC_DIR = 'src';
const DIST_DIR = 'lib';
const DIST_DEMO_DIR = 'demo-dist';
const PROJECT_NAME = 'zooAdventures';
const USE_SOURCEMAP = true;
// Build React component library
function config(format: ModuleFormat): RollupOptions[] {
const input = `./${SRC_DIR}/index.tsx`;
// Determine suffix of output files. For CommonJS builds we choose `.cjs`.
const ext = format === 'cjs' ? 'cjs' : 'js';
return [
{
input,
external: ['react'],
output: [
{
name: PROJECT_NAME,
file: `${DIST_DIR}/${format}/index.${ext}`,
format,
sourcemap: USE_SOURCEMAP,
},
{
name: PROJECT_NAME,
file: `${DIST_DIR}/${format}/index.min.js`,
format,
sourcemap: USE_SOURCEMAP,
plugins: [pluginTerser()],
},
],
plugins: [
pluginTypeScript(),
pluginCommonJS(),
pluginNodeResolve({
browser: true,
}),
pluginJSON(),
],
},
{
input,
output: {
file: `${DIST_DIR}/${format}/index.d.ts`,
format,
},
plugins: [pluginDts()],
},
];
}
// Build demo website using the component. This can be used for testing and
// served as a static page
function demoConfig(): RollupOptions[] {
const input = `./${SRC_DIR}/demo.tsx`;
return [
{
input,
output: {
name: PROJECT_NAME,
file: `${DIST_DEMO_DIR}/index.js`,
format: 'iife',
sourcemap: USE_SOURCEMAP,
},
plugins: [
pluginReplace({
preventAssignment: true,
values: {
// `graphql` package breaks here if we don't replace this as well
'globalThis.process.env.NODE_ENV': JSON.stringify('development'),
// `react` bundle
'process.env.NODE_ENV': JSON.stringify('development'),
},
}),
pluginTypeScript(),
pluginHTML({
title: PROJECT_NAME,
}),
pluginJSON(),
pluginNodeResolve({
browser: true,
}),
pluginCommonJS(),
],
},
];
}
export default [...config('esm'), ...config('cjs'), ...demoConfig()];