-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
73 lines (66 loc) · 2.18 KB
/
rollup.config.mjs
File metadata and controls
73 lines (66 loc) · 2.18 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
import { createESMConfig, createCJSConfig, collectSourceEntries } from '../../scripts/build/rollup.base.mjs';
import pkg from './package.json' with { type: 'json' };
const input = collectSourceEntries();
const isESM = process.env.BUILD_FORMAT === 'esm';
const isCJS = process.env.BUILD_FORMAT === 'cjs';
// External dependencies that should NOT be bundled
// These are peer dependencies of this package or its peer dependencies
const external = (id) => {
// Always external: React and related packages
if (id === 'react' || id === 'react-dom' || id.startsWith('react/') || id.startsWith('react-dom/')) {
return true;
}
// Always external: Next.js
if (id === 'next' || id.startsWith('next/')) {
return true;
}
// Always external: instantsearch packages (peer or devDependencies)
if (id === 'instantsearch.js' || id.startsWith('instantsearch.js/')) {
return true;
}
if (id === 'react-instantsearch' || id.startsWith('react-instantsearch/')) {
return true;
}
if (id === 'react-instantsearch-core' || id.startsWith('react-instantsearch-core/')) {
return true;
}
// Relative imports are not external
if (id.startsWith('.') || id.startsWith('/')) {
return false;
}
// Check regular dependencies
const deps = Object.keys(pkg.dependencies || {});
return deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
};
// When BUILD_FORMAT is set, only build that format
// Otherwise, build both (for watch mode)
const configs = [];
if (isESM || (!isESM && !isCJS)) {
configs.push(
createESMConfig({
input,
pkg,
outputDir: 'dist/es',
external,
// Preserve module structure so Next.js can tree-shake Server/Client Components
preserveModules: true,
})
);
}
if (isCJS || (!isESM && !isCJS)) {
configs.push(
createCJSConfig({
input,
pkg,
outputDir: 'dist/cjs',
external,
// Preserve module structure so bundlers can tree-shake Server/Client Components
preserveModules: true,
// Replace instantsearch.js/es imports with instantsearch.js/cjs for CJS build
replaceImports: {
'instantsearch.js/es': 'instantsearch.js/cjs',
},
})
);
}
export default configs;