-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
112 lines (106 loc) · 3.5 KB
/
Copy pathtsup.config.ts
File metadata and controls
112 lines (106 loc) · 3.5 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
109
110
111
112
import { resolve } from "node:path";
import type { Plugin as EsbuildPlugin } from "esbuild";
import { type Options, defineConfig } from "tsup";
// ── ESM build (existing, unchanged) ──────────────────────────────
const esmConfig: Options = {
entry: {
index: "src/index.ts",
"vast/index": "src/vast/index.ts",
"vmap/index": "src/vmap/index.ts",
"omid/index": "src/omid/index.ts",
"simid/index": "src/simid/index.ts",
"vpaid/index": "src/vpaid/index.ts",
"ima/index": "src/ima/index.ts",
"hls/index": "src/hls/index.ts",
"dash/index": "src/dash/index.ts",
"drm/index": "src/drm/index.ts",
"ssai/index": "src/ssai/index.ts",
"ui/index": "src/ui/index.ts",
"react/index": "src/react/index.ts",
"vue/index": "src/vue/index.ts",
},
onSuccess:
"mkdir -p dist/ui && cp src/ui/theme.css dist/ui/theme.css && cp src/ui/theme.css dist/vide.ui.css && for f in dist/index.mjs dist/*/index.mjs; do d=$(dirname $f); cp $f $d/index.js; done",
external: [
"hls.js",
"dashjs",
"react",
"react-dom",
"react/jsx-runtime",
"vue",
"svelte",
],
esbuildOptions(options) {
options.jsx = "automatic";
},
format: ["esm"],
dts: true,
clean: true,
minify: true,
treeshake: true,
splitting: true,
target: "es2022",
outExtension: () => ({ js: ".mjs" }),
};
// ── IIFE helpers ─────────────────────────────────────────────────
/** esbuild plugin that redirects hls.js/dashjs imports to globalThis shims. */
const globalShimPlugin: EsbuildPlugin = {
name: "global-shim",
setup(build) {
build.onResolve({ filter: /^hls\.js$/ }, () => ({
path: resolve("src/global/hls-shim.ts"),
}));
build.onResolve({ filter: /^dashjs$/ }, () => ({
path: resolve("src/global/dashjs-shim.ts"),
}));
},
};
const iifeBase: Partial<Options> = {
format: ["iife"],
outDir: "dist",
dts: false,
clean: false,
minify: true,
treeshake: true,
splitting: false,
target: "es2020",
platform: "browser",
outExtension: () => ({ js: ".js" }),
};
function iifeConfig(
entryName: string,
entryPath: string,
opts?: { globalName?: string; needsShims?: boolean },
): Options {
return {
...iifeBase,
entry: { [entryName]: entryPath },
globalName: opts?.globalName,
esbuildPlugins: opts?.needsShims ? [globalShimPlugin] : [],
};
}
// ── Export ────────────────────────────────────────────────────────
export default defineConfig([
esmConfig,
// All-in-one
iifeConfig("vide.global", "src/global/all.ts", {
globalName: "Vide",
needsShims: true,
}),
// Core only
iifeConfig("vide.core.global", "src/global/core.ts", {
globalName: "Vide",
}),
// Individual plugins (no globalName — they extend window.Vide)
iifeConfig("vide.hls.global", "src/global/hls.ts", { needsShims: true }),
iifeConfig("vide.dash.global", "src/global/dash.ts", { needsShims: true }),
iifeConfig("vide.vast.global", "src/global/vast.ts"),
iifeConfig("vide.vmap.global", "src/global/vmap.ts"),
iifeConfig("vide.drm.global", "src/global/drm.ts"),
iifeConfig("vide.ssai.global", "src/global/ssai.ts"),
iifeConfig("vide.omid.global", "src/global/omid.ts"),
iifeConfig("vide.simid.global", "src/global/simid.ts"),
iifeConfig("vide.vpaid.global", "src/global/vpaid.ts"),
iifeConfig("vide.ima.global", "src/global/ima.ts"),
iifeConfig("vide.ui.global", "src/global/ui.ts"),
]);