-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrolldown.config.js
More file actions
39 lines (34 loc) · 1.12 KB
/
Copy pathrolldown.config.js
File metadata and controls
39 lines (34 loc) · 1.12 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
import { defineConfig } from 'rolldown';
import { visualizer } from 'rollup-plugin-visualizer';
import pkg from './package.json' with { type: 'json' };
import path from 'node:path';
const allowedDependencies = new Set([
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
]);
export default defineConfig({
input: path.resolve(process.cwd(), 'src/index.ts'),
tsconfig: path.resolve(process.cwd(), 'tsconfig.build.json'),
output: {
dir: './dist',
format: 'es',
preserveModules: true,
preserveModulesRoot: 'src',
sourcemap: true,
},
plugins: [visualizer({ output: 'stats.html' })],
external(id) {
if (id.startsWith('.') || path.isAbsolute(id)) return false;
if (id.startsWith('@/')) return false;
if (id.startsWith('node:')) return true;
const dependency = id.split('/')[0].startsWith('@')
? id.split('/').slice(0, 2).join('/')
: id.split('/')[0];
if (!allowedDependencies.has(dependency)) {
throw new Error(
`Dependency "${dependency}" is used but not listed in dependencies/peerDependencies`
);
}
return true;
},
});