44import tailwindcss from "@tailwindcss/vite" ;
55import react from "@vitejs/plugin-react-swc" ;
66import { defineConfig } from "electron-vite" ;
7+ import path from "path" ;
78import { ViteImageOptimizer } from "vite-plugin-image-optimizer" ;
89import svgr from "vite-plugin-svgr" ;
910import tsconfigPaths from "vite-tsconfig-paths" ;
1011
1112// from our electron build
1213const CHROME = "chrome140" ;
1314const NODE = "node22" ;
15+ const MERMAID_CORE = path . resolve ( __dirname , "node_modules/mermaid/dist/mermaid.core.mjs" ) ;
1416
15- // for debugging
16- // target is like -- path.resolve(__dirname, "frontend/app/workspace/workspace-layout-model.ts");
17- function whoImportsTarget ( target : string ) {
17+ function streamdownMermaidFix ( ) {
1818 return {
19- name : "who-imports-target" ,
20- buildEnd ( ) {
21- // Build reverse graph: child -> [importers...]
22- const parents = new Map < string , string [ ] > ( ) ;
23- for ( const id of ( this as any ) . getModuleIds ( ) ) {
24- const info = ( this as any ) . getModuleInfo ( id ) ;
25- if ( ! info ) continue ;
26- for ( const child of [ ...info . importedIds , ...info . dynamicallyImportedIds ] ) {
27- const arr = parents . get ( child ) ?? [ ] ;
28- arr . push ( id ) ;
29- parents . set ( child , arr ) ;
30- }
31- }
32-
33- // Walk upward from TARGET and print paths to entries
34- const entries = [ ...parents . keys ( ) ] . filter ( ( id ) => {
35- const m = ( this as any ) . getModuleInfo ( id ) ;
36- return m ?. isEntry ;
37- } ) ;
38-
39- const seen = new Set < string > ( ) ;
40- const stack : string [ ] = [ ] ;
41- const dfs = ( node : string ) => {
42- if ( seen . has ( node ) ) return ;
43- seen . add ( node ) ;
44- stack . push ( node ) ;
45- const ps = parents . get ( node ) || [ ] ;
46- if ( ps . length === 0 ) {
47- // hit a root (likely main entry or plugin virtual)
48- console . log ( "\nImporter chain:" ) ;
49- stack
50- . slice ( )
51- . reverse ( )
52- . forEach ( ( s ) => console . log ( " ↳" , s ) ) ;
53- } else {
54- for ( const p of ps ) dfs ( p ) ;
55- }
56- stack . pop ( ) ;
57- } ;
58-
59- if ( ! parents . has ( target ) ) {
60- console . log ( `[who-imports] TARGET not in MAIN graph: ${ target } ` ) ;
61- } else {
62- dfs ( target ) ;
63- }
64- } ,
65- async resolveId ( id : any , importer : any ) {
66- const r = await ( this as any ) . resolve ( id , importer , { skipSelf : true } ) ;
67- if ( r ?. id === target ) {
68- console . log ( `[resolve] ${ importer } -> ${ id } -> ${ r . id } ` ) ;
69- }
70- return null ;
19+ name : "streamdown-mermaid-fix" ,
20+ enforce : "pre" as const ,
21+ transform ( code : string , id : string ) {
22+ if ( ! id . includes ( "node_modules/streamdown" ) ) return null ;
23+ if ( ! code . includes ( "import('mermaid')" ) ) return null ;
24+ return code . replaceAll ( "import('mermaid')" , `import('/@fs${ MERMAID_CORE } ')` ) ;
7125 } ,
7226 } ;
7327}
@@ -89,6 +43,7 @@ export default defineConfig({
8943 resolve : {
9044 alias : {
9145 "@" : "frontend" ,
46+ mermaid : path . resolve ( __dirname , "node_modules/mermaid/dist/mermaid.js" ) ,
9247 } ,
9348 } ,
9449 server : {
@@ -147,8 +102,25 @@ export default defineConfig({
147102 } ,
148103 } ,
149104 } ,
105+ resolve : {
106+ alias : {
107+ "style-to-js$" : path . resolve ( __dirname , "frontend/style-to-js-compat.ts" ) ,
108+ "extend$" : path . resolve ( __dirname , "frontend/extend-compat.ts" ) ,
109+ } ,
110+ } ,
150111 optimizeDeps : {
151- include : [ "monaco-yaml/yaml.worker.js" ] ,
112+ include : [
113+ "monaco-yaml/yaml.worker.js" ,
114+ "style-to-js" ,
115+ "style-to-object" ,
116+ "react-markdown" ,
117+ "rehype-raw" ,
118+ "rehype-sanitize" ,
119+ "hast-util-to-estree" ,
120+ "hast-util-to-jsx-runtime" ,
121+ "extend"
122+ ] ,
123+ exclude : [ "mermaid" , "streamdown" ] ,
152124 } ,
153125 server : {
154126 open : false ,
@@ -176,6 +148,7 @@ export default defineConfig({
176148 } ,
177149 plugins : [
178150 tsconfigPaths ( ) ,
151+ streamdownMermaidFix ( ) ,
179152 { ...ViteImageOptimizer ( ) , apply : "build" } ,
180153 svgr ( {
181154 svgrOptions : { exportType : "default" , ref : true , svgo : false , titleProp : true } ,
0 commit comments