-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.js
More file actions
131 lines (119 loc) · 4.39 KB
/
Copy pathvite.config.js
File metadata and controls
131 lines (119 loc) · 4.39 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
import { fileURLToPath, URL } from "node:url";
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { defineConfig } from 'vite'
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import viteCompression from 'vite-plugin-compression';
import { viteStaticCopy } from 'vite-plugin-static-copy';
// Determine the correct path for WebSharedComponents
// When standalone (own .git directory): use ./WebSharedComponents
// When used as submodule (.git is a file pointing to parent): use ../WebSharedComponents
function getWebSharedComponentsPath() {
const parentPath = path.resolve(__dirname, "../WebSharedComponents");
const localPath = path.resolve(__dirname, "./WebSharedComponents");
const gitPath = path.resolve(__dirname, ".git");
// If .git is a file, this is a submodule -> use parent WebSharedComponents
// If .git is a directory, this is standalone -> use local WebSharedComponents
const isSubmodule = fs.existsSync(gitPath) && fs.statSync(gitPath).isFile();
if (isSubmodule && fs.existsSync(parentPath)) {
return parentPath;
}
return localPath;
}
// Resolved at config-load time (top-level await is fine for Vite ESM config).
const masRegen = (await import(
pathToFileURL(path.join(getWebSharedComponentsPath(), 'build-tools', 'vite-plugin-mas-regen.js')).href
)).default;
// 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]';
}
// default value
// ref: https://rollupjs.org/guide/en/#outputassetfilenames
return 'assets/[name]-[hash][extname]';
},
},
},
},
optimizeDeps: {
disabled: false,
},
worker: {
format: 'es',
},
publicDir: 'src/public',
plugins: [
// Auto-regen MAS.ts when MAS schemas change. See WebSharedComponents/build-tools.
masRegen({
targets: [
fileURLToPath(new URL('./src/assets/ts/MAS.ts', import.meta.url)),
path.join(getWebSharedComponentsPath(), 'assets', 'ts', 'MAS.ts'),
],
}),
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag.includes("py-"),
whitespace: "preserve",
},
},
}),
vueJsx(),
viteCompression({filter: '/\.(js|mjs|json|css|html|wasm)$/i'}),
// Copy WASM files from assets to wasm/ folder in build output
viteStaticCopy({
targets: [
{
src: 'src/assets/js/libMKF.wasm.js',
dest: 'wasm'
},
{
src: 'src/assets/js/libMKF.wasm.wasm',
dest: 'wasm'
},
{
src: 'src/assets/js/mvbpp.js',
dest: 'wasm'
},
{
src: 'src/assets/js/mvbpp.wasm',
dest: 'wasm'
}
]
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
"/WebSharedComponents": getWebSharedComponentsPath(),
},
},
server: {
proxy: {
'/api': {
target: 'https://localhost:8888',
changeOrigin: true,
secure: false,
ws: true,
}
}
}
})