-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
64 lines (58 loc) · 1.64 KB
/
Copy pathtsdown.config.ts
File metadata and controls
64 lines (58 loc) · 1.64 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
import { defineConfig } from "tsdown";
import type { Plugin } from "rolldown";
import copy from "rollup-plugin-copy";
import { removeTestIdsPlugin } from "../shared/remove-test-ids-plugin.ts";
import { dayJsEsmReplacePlugin } from "../shared/dayjs-esm-replace-plugin.ts";
import { markAsExternalPlugin } from "../shared/mark-as-external-plugin.ts";
const ANTD_TARGET_REGEX =
/\/src\/components\/antd\/(antd|calendar|datePicker|timePicker).*/;
/**
* Replaces CJS imports (antd/lib/, rc-picker/lib/) with ESM equivalents (antd/es/, rc-picker/es/)
*/
const antdLibToEsPlugin = (): Plugin => ({
name: "antd-lib-2-es-module-replacement",
renderChunk(code, chunk, options) {
if (options.format === "cjs") return null;
if (!ANTD_TARGET_REGEX.test(chunk.fileName)) return null;
return {
code: code
.replace(/antd\/lib\//g, "antd/es/")
.replace(/rc-picker\/lib\//g, "rc-picker/es/"),
map: null,
};
},
});
export default defineConfig((options) => ({
entry: ["src/index.tsx"],
outputOptions: {
codeSplitting: false,
keepNames: true,
},
banner: {
js: '"use client"',
},
sourcemap: true,
clean: false,
minify: false,
format: ["cjs", "esm"],
outExtensions({ format }) {
return {
js: format === "cjs" ? ".cjs" : ".mjs",
};
},
platform: "browser",
plugins: [
removeTestIdsPlugin,
antdLibToEsPlugin(),
dayJsEsmReplacePlugin,
copy({
targets: [{ src: "src/assets/styles/reset.css", dest: "dist" }],
hook: "writeBundle",
}),
markAsExternalPlugin,
],
loader: {
".svg": "dataurl",
},
onSuccess: options.watch ? "pnpm types" : undefined,
}));