-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
143 lines (141 loc) · 6.23 KB
/
Copy pathvite.config.js
File metadata and controls
143 lines (141 loc) · 6.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { resolve, dirname } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import svgLoader from 'vite-svg-loader'
import postcssPresetEnv from 'postcss-preset-env'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// Variant-(a) port from mark-electron@v1.2.3 electron.vite.config.js
// renderer block. Tauri 2 conventions: dev server on :1420, strict port,
// build output to src/renderer/dist (matches frontendDist in tauri.conf.json).
//
// Differences vs Electron config:
// - root pinned to src/renderer (where index.html lives)
// - vite-plugin-electron-renderer dropped (was already removed in v1.2.1)
// - process.platform / process.env.NODE_ENV define kept: third-party libs
// (@hfelix/electron-localshortcut utils.js dead-code, etc.) still
// reference them at module-load time. Build-time substitution avoids
// needing a runtime process global in WKWebView.
// - manualChunks copied verbatim — same vendor split that v1.2.x used.
export default defineConfig({
root: resolve(__dirname, 'src/renderer'),
publicDir: resolve(__dirname, 'src/renderer/public'),
assetsInclude: ['**/*.md'],
resolve: {
alias: {
'@': resolve(__dirname, 'src/renderer/src'),
common: resolve(__dirname, 'src/common'),
muya: resolve(__dirname, 'src/muya'),
// main_renderer alias preserved as historical no-op — original
// pointed at src/main, which Tauri does not have. Kept so any
// residual import that escapes the M-013 IPC bridge fails loud
// at build time rather than silently picking up stale paths.
main_renderer: resolve(__dirname, 'src/_main_renderer_REMOVED_use_ipc'),
// Browser polyfills for Node-builtin imports surviving in vendored
// libs (muya/lib/utils path, sequence-diagram-snap fs/path stubs).
path: 'path-browserify',
fs: resolve(__dirname, 'src/renderer/src/util/fs-shim.js'),
// F-MAIN-ENTRY-DISABLED close (2026-04-29):
// Build-time replacements for v1.2.3 renderer's Electron-only
// imports. Real impls in src/renderer/src/_shims/ —
// electron-log/renderer + electron-log → console facade;
// @hfelix/electron-localshortcut + /src/atom-keymap deep import →
// 4-fn pure-JS replacement. See _shims/electron-log.js +
// _shims/hfelix-localshortcut.js.
'electron-log/renderer': resolve(__dirname, 'src/renderer/src/_shims/electron-log.js'),
'electron-log': resolve(__dirname, 'src/renderer/src/_shims/electron-log.js'),
'@hfelix/electron-localshortcut/src/atom-keymap': resolve(__dirname, 'src/renderer/src/_shims/hfelix-localshortcut.js'),
'@hfelix/electron-localshortcut': resolve(__dirname, 'src/renderer/src/_shims/hfelix-localshortcut.js')
},
extensions: ['.mjs', '.js', '.ts', '.json', '.vue']
},
define: {
'__APP_VERSION__': JSON.stringify(process.env.npm_package_version || '0.0.0'),
'process.platform': JSON.stringify(process.platform),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
// F-DEV-MODE-WHITE-SCREEN root cause: dragula → custom-event references
// the Node-only `global`. Production rollup tree-shakes it out; dev
// mode doesn't. globalThis is available in both Node and browser
// (and Tauri's webview), so this define makes both surfaces happy.
global: 'globalThis'
},
plugins: [
vue(),
svgLoader()
],
server: {
port: 1420,
strictPort: true
},
build: {
outDir: resolve(__dirname, 'src/renderer/dist'),
emptyOutDir: true,
chunkSizeWarningLimit: 1024,
rollupOptions: {
// Multi-entry: main app + perf harness. Both entries live under
// src/renderer (the configured Vite root). vite build emits
// src/renderer/dist/{index.html, bench/index.html}; Tauri's
// frontendDist points at src/renderer/dist so both ship in the
// bundle.
input: {
// F-MAIN-ENTRY-DISABLED closed 2026-04-29. Renderer-local shims:
// - electron-log + electron-log/renderer → _shims/electron-log.js
// - @hfelix/electron-localshortcut + /src/atom-keymap →
// _shims/hfelix-localshortcut.js
// - main/preferences/schema.json → _shims/preferences/schema.json
// - window.* contextBridge surface → _shims/install-window-globals
// (imported FIRST in main.js so renderer code resolves
// window.fileUtils.X / window.electron.X correctly)
main: resolve(__dirname, 'src/renderer/index.html'),
bench: resolve(__dirname, 'src/renderer/bench/index.html'),
baseline: resolve(__dirname, 'src/renderer/bench/baseline/index.html')
},
// Externals trimmed: only electron-store / electron-updater /
// @electron/* / electron itself remain. electron-log + @hfelix
// moved to alias-replaced shims above.
external: [
/^electron-store(\/.*)?$/,
/^electron-updater(\/.*)?$/,
/^@electron\/.*$/,
/^electron$/
],
output: {
manualChunks: (id) => {
if (!id.includes('node_modules')) return undefined
if (/[\\/]node_modules[\\/](vue|@vue|vue-router|pinia)[\\/]/.test(id)) {
return 'vendor-vue'
}
if (/[\\/]node_modules[\\/](element-plus|@element-plus)[\\/]/.test(id)) {
return 'vendor-element-plus'
}
if (/[\\/]node_modules[\\/]codemirror[\\/]/.test(id)) {
return 'vendor-codemirror'
}
if (/[\\/]node_modules[\\/]katex[\\/]/.test(id)) {
return 'vendor-katex'
}
// prismjs: kept in entry bundle — language plugins side-effect
// onto Prism core at module top-level, splitting breaks load order.
if (/[\\/]node_modules[\\/](turndown|marked|markdown-it|dompurify)[\\/]/.test(id)) {
return 'vendor-markdown'
}
if (/[\\/]node_modules[\\/](vega|vega-lite|vega-embed|d3-[a-z-]+|d3)[\\/]/.test(id)) {
return 'vendor-vega'
}
return undefined
}
}
}
},
css: {
postcss: {
plugins: [
postcssPresetEnv({
stage: 0,
features: { 'nesting-rules': true }
})
]
}
}
})