-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.renderer.config.ts
More file actions
86 lines (82 loc) · 2.65 KB
/
Copy pathvite.renderer.config.ts
File metadata and controls
86 lines (82 loc) · 2.65 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
import { defineConfig, type Plugin } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";
/**
* Vite plugin that captures extracted CSS and inlines it as a string export
* in the JS bundle. This is necessary because VS Code notebook renderers only
* load the JS entrypoint — a separate CSS file would never be loaded.
*
* The CSS string is made available via `import cssText from 'virtual:renderer-css'`
* so the renderer can inject it into its Shadow DOM.
*/
function inlineCssPlugin(): Plugin {
const virtualId = "virtual:renderer-css";
const resolvedVirtualId = "\0" + virtualId;
// Unique marker that survives bundler transforms (inlineDynamicImports
// converts `export default "..."` into `const cssText = "..."`)
const CSS_PLACEHOLDER = "__RENDERER_CSS_PLACEHOLDER_a9f3e7__";
return {
name: "inline-css-into-js",
enforce: "post" as const,
resolveId(id) {
if (id === virtualId) return resolvedVirtualId;
},
load(id) {
if (id === resolvedVirtualId) {
return `export default "${CSS_PLACEHOLDER}"`;
}
},
generateBundle(_, bundle) {
// Collect and remove all CSS assets
let extractedCss = "";
for (const [key, chunk] of Object.entries(bundle)) {
if (key.endsWith(".css") && chunk.type === "asset") {
extractedCss += chunk.source;
delete bundle[key];
}
}
// Replace the placeholder marker in the JS entry with the real CSS
for (const chunk of Object.values(bundle)) {
if (chunk.type === "chunk" && chunk.isEntry) {
chunk.code = chunk.code.replace(`"${CSS_PLACEHOLDER}"`, JSON.stringify(extractedCss));
}
}
},
};
}
export default defineConfig({
plugins: [vue(), inlineCssPlugin()],
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
__APP_VERSION__: JSON.stringify("vendored"),
},
esbuild: {
jsx: "transform",
jsxFactory: "jsx",
jsxFragment: "Fragment",
jsxInject: `import { jsx, Fragment } from 'fibrae/jsx-runtime'`,
},
build: {
lib: {
entry: resolve(__dirname, "src/features/notebook/renderer/index.tsx"),
formats: ["es"],
fileName: "sql-renderer",
},
outDir: "src/features/notebook/renderer-dist",
emptyOutDir: true,
minify: false,
sourcemap: true,
rollupOptions: {
external: ["vscode-notebook-renderer"],
output: {
// Disable code splitting - VS Code notebook renderers can't resolve relative chunk imports
inlineDynamicImports: true,
},
},
},
resolve: {
alias: {
"@": resolve(__dirname, "src/features/notebook/renderer/pev2"),
},
},
});