-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrolldown.config.mts
More file actions
62 lines (59 loc) · 1.62 KB
/
rolldown.config.mts
File metadata and controls
62 lines (59 loc) · 1.62 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
import { defineConfig, type RolldownOptions } from 'rolldown';
import { addDirective } from 'rollup-plugin-add-directive';
const createBuild = ({
inPath = '',
outPath = inPath,
inFile = 'index.ts'
}: { inPath?: string; outPath?: string; inFile?: string } = {}): RolldownOptions => ({
external: ['react', 'react-dom', 'use-sync-external-store/shim', 'immer'],
plugins: [
{
name: 'rolldown-plugin-replace-code',
renderChunk: (code, chunk) => {
if (!chunk.name.endsWith('reactShim')) return null;
return code.replace(
'use-sync-external-store/shim',
'use-sync-external-store/shim/index.js'
);
}
}
],
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false
},
input: `src/${inPath}${inFile}`,
output: [
{
dir: `dist/cjs/${outPath}`,
format: 'cjs',
entryFileNames: '[name].cjs',
preserveModules: true,
// Temporary workaround until this issue is fixed:
// https://github.com/rolldown/rolldown/issues/5865
plugins: [addDirective({ directive: "'use strict';" })]
},
{
dir: `dist/esm/${outPath}`,
format: 'esm',
entryFileNames: '[name].mjs',
preserveModules: true
}
],
transform: {
target: ['es2020'],
assumptions: {
noDocumentAll: true
},
define: {
'process.env.NODE_ENV': 'process.env.NODE_ENV'
}
}
});
export default defineConfig([
createBuild(),
createBuild({ inPath: 'middleware/' }),
createBuild({ inPath: 'middleware/', inFile: 'immer.ts' }),
createBuild({ inPath: 'plugin/' }),
createBuild({ inPath: 'shim/' })
]);