-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrollup.config.js
More file actions
108 lines (102 loc) · 2.67 KB
/
rollup.config.js
File metadata and controls
108 lines (102 loc) · 2.67 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Custom plugin to import worklet files as strings
function workletAsString() {
return {
name: 'worklet-as-string',
resolveId(id) {
if (id.includes('?worklet-code')) {
return id;
}
return null;
},
load(id) {
if (id.includes('?worklet-code')) {
const distFile = 'dist/DeepFilterWorklet.js';
const distPath = resolve(__dirname, distFile);
try {
const code = readFileSync(distPath, 'utf-8');
// Return the code as a string export
return `export default ${JSON.stringify(code)};`;
} catch (e) {
// During initial build, the dist file doesn't exist yet
// Return a placeholder that will be updated in a second build pass
console.warn(`Warning: ${distFile} not found. You may need to run build twice.`);
return `export default '';`;
}
}
return null;
}
};
}
export default [
// Worklet bundle - Build this first
{
input: 'src/worklet/DeepFilterWorklet.ts',
output: {
file: 'dist/DeepFilterWorklet.js',
format: 'iife',
sourcemap: false,
},
plugins: [
nodeResolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.build.json',
declaration: false,
sourceMap: false,
target: 'ES2020',
}),
],
},
// Main library bundle - Build this second (after worklet file exists)
{
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
sourcemap: false,
},
{
file: 'dist/index.esm.js',
format: 'esm',
sourcemap: false,
},
],
external: ['livekit-client'],
plugins: [
workletAsString(), // Load worklet file as string
nodeResolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
sourceMap: false,
target: 'ES2020',
}),
],
},
// Type definitions - Build this last
{
input: 'src/index.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [
dts({
respectExternal: true,
compilerOptions: {
declaration: true,
declarationMap: false,
}
})
],
external: ['livekit-client'],
},
];