-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
74 lines (71 loc) · 2.23 KB
/
Copy pathtsdown.config.ts
File metadata and controls
74 lines (71 loc) · 2.23 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
import { defineConfig } from "tsdown";
export default defineConfig({
entry: ["src/index.ts"],
format: ["cjs", "esm"],
fixedExtension: false,
tsconfig: "tsconfig.src.json",
dts: {
sourcemap: false,
},
sourcemap: true,
// The CJS declarations are emitted in a separate pass, so their output can
// disable source maps without affecting the runtime bundle.
outputOptions(options, _format, { cjsDts }) {
if (!cjsDts) return;
return {
...options,
sourcemap: false,
};
},
clean: true,
treeshake: true,
minify: false,
deps: {
onlyBundle: false,
alwaysBundle: [
// Always bundle internal packages
/^@internal/,
// Always bundle ESM-only packages
"nanoid",
"p-limit",
],
dts: {
// The TypeScript 7 declaration emitter consumes referenced package declarations.
neverBundle: [/^@internal/],
},
},
// rolldown injects its own `__require` helper in the ESM output as
// `createRequire(import.meta.url)` with no fallback. When this ESM bundle is
// re-bundled into a CJS consumer (e.g. the webapp server), esbuild replaces
// `import.meta.url` with `undefined`, so `createRequire(undefined)` throws at
// startup. Patch the helper to fall back to a valid path, matching the
// fallback the previous tsup banner provided.
plugins: [
// The ESM declarations share an output pass with the runtime bundle.
// Remove their dangling map comment while retaining runtime source maps.
{
name: "strip-declaration-sourcemap-comments",
generateBundle(_options, bundle) {
for (const output of Object.values(bundle)) {
if (output.type !== "chunk" || !/\.d\.(?:c|m)?ts$/.test(output.fileName)) {
continue;
}
output.code = output.code.replace(/\n?\/\/# sourceMappingURL=.*$/m, "");
}
},
},
{
name: "resilient-create-require",
renderChunk(code: string) {
if (!code.includes("createRequire(import.meta.url)")) return null;
return {
code: code.replaceAll(
"createRequire(import.meta.url)",
"createRequire(import.meta.url || process.cwd() + '/index.js')"
),
map: null,
};
},
},
],
});