-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.js
More file actions
144 lines (138 loc) · 6.34 KB
/
Copy pathvite.config.js
File metadata and controls
144 lines (138 loc) · 6.34 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
144
import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import path from 'node:path';
import vue from '@vitejs/plugin-vue'
import viteCompression from 'vite-plugin-compression';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import masRegen from './WebSharedComponents/build-tools/vite-plugin-mas-regen.js';
// https://vitejs.dev/config/
export default defineConfig({
// Include WASM-related files as assets so they're copied to the build output
assetsInclude: ['**/*.wasm'],
build: {
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: ({name}) => {
if (/\.(gif|jpe?g|png|svg)$/.test(name ?? '')){
return 'assets/images/[name]-[hash][extname]';
}
if (/\.css$/.test(name ?? '')) {
return 'assets/css/[name]-[hash][extname]';
}
// Keep WASM files in assets/wasm without hash for predictable paths
if (/\.wasm$/.test(name ?? '')) {
return 'assets/wasm/[name][extname]';
}
return 'assets/[name]-[hash][extname]';
},
},
},
},
// Worker configuration - use ES modules format instead of IIFE
worker: {
format: 'es',
rollupOptions: {
output: {
entryFileNames: 'assets/workers/[name]-[hash].js',
chunkFileNames: 'assets/workers/[name]-[hash].js',
},
},
resolve: {
alias: [
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url))
},
],
},
},
css: {
preprocessorOptions: {
scss: {
quietDeps: true,
},
},
},
publicDir: 'src/public',
plugins: [
// Auto-regenerate MAS.ts from MAS schemas when schemas are newer than
// the existing MAS.ts. Catches schema drift at dev-server startup
// (and at build time) instead of via runtime errors deep in WASM.
masRegen({
// The MAS / PEAS schemas the engine is built with. Defaults to MKF's MAS + PEAS
// submodules next to this checkout; OM_MAS_SCHEMAS_DIR / OM_PEAS_SCHEMAS_DIR point
// at the engine's own tree when that checkout lags MKF main's pins.
schemasDir: process.env.OM_MAS_SCHEMAS_DIR || undefined,
peasDir: process.env.OM_PEAS_SCHEMAS_DIR || undefined,
targets: [
fileURLToPath(new URL('./WebSharedComponents/assets/ts/MAS.ts', import.meta.url)),
fileURLToPath(new URL('./MagneticBuilder/src/assets/ts/MAS.ts', import.meta.url)),
fileURLToPath(new URL('./MagneticBuilder/WebSharedComponents/assets/ts/MAS.ts', import.meta.url)),
],
// JSON Schema bundle for the MAS sentry (WebSharedComponents/assets/js/masValidator.js).
schemaBundleTarget: fileURLToPath(new URL('./WebSharedComponents/assets/js/masSchemas.json', import.meta.url)),
// ABT #1697: the MKF / MAS / PEAS commits the engines are built from and their
// hashes (scripts/record-engine-manifest.mjs). The build fails when MAS.ts or
// masSchemas.json come from other MAS / PEAS commits, or an engine file changed
// without the manifest being re-recorded.
engineManifest: fileURLToPath(new URL('./src/assets/js/engineManifest.json', import.meta.url)),
}),
vue(),
viteCompression({filter: /\.(js|mjs|json|css|html|wasm)$/i}),
// Copy WASM files from assets to wasm/ folder served at /wasm/
viteStaticCopy({
targets: [
{ src: 'src/assets/js/libMKF.wasm.js', dest: 'wasm' },
{ src: 'src/assets/js/libMKF.wasm.wasm', dest: 'wasm' },
// webKirchhoff (converter models): built from the Kirchhoff repo (`ninja libKirchhoff`
// in build-wasm-kh -> kirchhoff.js). It is an -sSINGLE_FILE=1 build: the wasm is
// embedded in the one .js, there is NO separate libKirchhoff.wasm (a missing target
// here makes vite-plugin-static-copy abort the WHOLE list and nothing gets served).
{ src: 'src/assets/js/libKirchhoff.js', dest: 'wasm' },
{ src: 'src/assets/js/libInsulationCoordinator.wasm.js', dest: 'wasm' },
{ src: 'src/assets/js/libInsulationCoordinator.wasm.wasm', dest: 'wasm' },
{ src: 'src/assets/js/mvbpp.js', dest: 'wasm' },
{ src: 'src/assets/js/mvbpp.wasm', dest: 'wasm' },
]
}),
],
resolve: {
// Force a single instance of these shared deps so MagneticBuilder's
// node_modules don't ship a second copy. Two copies = two module-level
// singletons (Pinia activePinia, PrimeVue config) = production-only
// "Cannot read properties of undefined" errors.
dedupe: ['vue', 'pinia', 'primevue', '@primeuix/themes', 'vue-router'],
alias: [
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url))
},
{
find: 'WebSharedComponents',
replacement: fileURLToPath(new URL('./WebSharedComponents', import.meta.url))
},
],
},
server: {
fs: { allow: ['..'] },
watch: { usePolling: true, interval: 1000 },
// No hardcoded HMR port: vite falls back to 5174+ when 5173 is taken
// (another dev server on the box), and a pinned 5173 then makes every
// page open a doomed HMR socket — a console error in every Playwright
// run. Omitting `port` lets the client follow the resolved server port.
hmr: {
protocol: 'ws',
host: 'localhost',
},
proxy: {
'/api': {
target: 'https://localhost:8888',
changeOrigin: true,
secure: false,
ws: true,
}
}
}
})