-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
78 lines (74 loc) · 1.8 KB
/
Copy pathrollup.config.js
File metadata and controls
78 lines (74 loc) · 1.8 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
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { builtinModules } from 'module';
// Custom plugin to transform dynamic imports in ESM build
function transformDynamicImports() {
return {
name: 'transform-dynamic-imports',
transform(code, id) {
// Only transform ESM files
if (!id.endsWith('.js')) return null;
// Replace .js with .mjs in dynamic imports using URL
return {
code: code.replace(
/new URL\(['"](.+?)\.js['"]/g,
(match, p1) => `new URL('${p1}.mjs'`
),
map: null
};
}
};
}
const external = [
...builtinModules,
...builtinModules.map(m => `node:${m}`),
// Add your dependencies here if you want them external (e.g., 'jsdom')
'jsdom',
'is-empty-dir',
'deep-equal-check',
'colors',
'diff',
'file-system'
];
export default [
// ESM build
{
input: [
'src/index.js',
'src/run-assertions/worker-thread.js'
],
output: {
dir: 'dist/esm',
format: 'esm',
entryFileNames: '[name].mjs',
chunkFileNames: '[name]-[hash].mjs',
sourcemap: true,
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
},
external,
plugins: [transformDynamicImports(), resolve(), commonjs(), json()]
},
// CJS build
{
input: [
'src/index.js',
'src/run-assertions/worker-thread.js'
],
output: {
dir: 'dist/cjs',
format: 'cjs',
entryFileNames: '[name].cjs',
chunkFileNames: '[name]-[hash].cjs',
sourcemap: true,
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
},
external,
plugins: [resolve(), commonjs(), json()]
}
];