-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrolldown.config.mjs
79 lines (72 loc) · 1.68 KB
/
rolldown.config.mjs
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
// @ts-check
import path from "node:path";
import { defineConfig } from "rolldown";
import UnpluginIsolatedDecl from "unplugin-isolated-decl/rolldown";
import pkg from "./package.json" with { type: "json" };
const EXTERNAL_DEPENDENCIES = [
...Object.keys(pkg.dependencies || {}),
...(("peerDependencies" in pkg && typeof pkg.peerDependencies === "object" && pkg.peerDependencies != null) ? Object.keys(pkg.peerDependencies) : []),
];
/**
* @type {import('rolldown').Plugin}
*/
const ExternalPlugin = {
name: "external-deps",
resolveId(id, _, { isEntry }) {
if (isEntry) {
return;
}
let shouldExternal = !path.isAbsolute(id) && id[0] !== ".";
shouldExternal ||= EXTERNAL_DEPENDENCIES.some((dep) => id === dep || id.startsWith(`${dep}/`));
if (shouldExternal) {
return {
id,
external: true,
};
}
},
};
export default defineConfig([
{
input: {
index: "src/index.ts",
cli: "src/cli.ts",
},
output: {
dir: "dist",
format: "esm",
sourcemap: false,
entryFileNames: "[name].mjs",
chunkFileNames: "chunk-[hash].mjs",
},
platform: "node",
resolve: {
extensionAlias: {
".js": [".ts", ".js"],
},
},
plugins: [UnpluginIsolatedDecl(), ExternalPlugin],
},
{
input: {
index: "src/index.ts",
},
output: {
dir: "dist",
format: "cjs",
sourcemap: false,
entryFileNames: "[name].cjs",
chunkFileNames: "chunk-[hash].cjs",
},
platform: "node",
resolve: {
extensionAlias: {
".js": [".ts", ".js"],
},
},
plugins: [
UnpluginIsolatedDecl(),
ExternalPlugin,
],
},
]);