Repository navigation
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
88 lines (80 loc) · 2.14 KB
/
Copy pathrollup.config.mjs
File metadata and controls
88 lines (80 loc) · 2.14 KB
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
import {readFileSync} from 'node:fs';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
const {version: VERSION} = JSON.parse(readFileSync('./package.json', 'utf-8'));
const external = ['react', 'react-dom', 'react/jsx-runtime', 'fast-deep-equal'];
const plugins = [
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.build.json',
declaration: false,
declarationDir: undefined
}),
replace({
preventAssignment: true,
include: ['src/version.ts'],
values: {
__PACKAGE_VERSION__: VERSION
}
})
];
const entries = {
index: './src/index.ts',
'server/index': './src/server/index.ts',
'3d/index': './src/3d/index.ts'
};
// One ESM build for every entry, so the modules they share (the APIProvider
// and map contexts above all) are emitted once as chunks and each entry
// imports the same instance. Built one entry at a time, `/3d` and the root
// each carried their own `APIProviderContext`, and a `Map3D` imported from
// `/3d` could not see the `APIProvider` imported from the root.
const esmConfig = {
input: entries,
output: {
dir: 'dist',
format: 'es',
entryFileNames: '[name].modern.mjs',
chunkFileNames: 'chunks/[name]-[hash].mjs',
sourcemap: true
},
external,
plugins
};
// UMD cannot code-split; each entry stays self-contained.
const umdConfig = (input, outputBase) => ({
input,
output: {
file: `${outputBase}.umd.js`,
format: 'umd',
name: 'ReactGoogleMaps',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react/jsx-runtime': 'React',
'fast-deep-equal': 'fastDeepEqual'
},
sourcemap: true
},
external,
plugins
});
const dtsConfig = (input, outputBase) => ({
input,
output: {
file: `${outputBase}.d.ts`,
format: 'es'
},
external,
plugins: [dts()]
});
export default [
esmConfig,
...Object.entries(entries).flatMap(([name, input]) => [
umdConfig(input, `./dist/${name}`),
dtsConfig(input, `./dist/${name}`)
])
];