-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvite.config.ts
More file actions
94 lines (89 loc) · 2.85 KB
/
vite.config.ts
File metadata and controls
94 lines (89 loc) · 2.85 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
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
// @ts-ignore
import vue from "@vitejs/plugin-vue";
// @ts-ignore
import vueJsx from "@vitejs/plugin-vue-jsx";
import { name, version } from "./package.json";
import { execSync } from "child_process";
import { viteStaticCopy } from "vite-plugin-static-copy";
import { dirname, join } from "path";
import { version as pyodideVersion } from "pyodide";
let wantsSmallBuild = process.env.YACV_SMALL_BUILD == "true";
// Helper to safely get git info
function getGitInfo(command: string, fallback: string): string {
try {
return execSync(command, { stdio: "pipe" }).toString().trim();
} catch (e) {
return fallback;
}
}
// https://vitejs.dev/config/
export default defineConfig({
base: "",
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag: string) => tag == "model-viewer",
},
},
}),
vueJsx(),
viteStaticCopyPyodide(),
],
optimizeDeps: { exclude: ["pyodide"] },
resolve: {
alias: {
// @ts-ignore
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
build: {
assetsDir: ".", // Support deploying to a subdirectory using relative URLs
cssCodeSplit: false, // Small enough to inline
chunkSizeWarningLimit: 1024, // KB. Three.js is big. Draco is even bigger but not likely to be used.
sourcemap: true, // For debugging production
rollupOptions: {
external: wantsSmallBuild
? [
// Exclude some large optional dependencies if small build is requested (for embedding in python package)
"pyodide",
/.*\/pyodide-worker.*/,
"monaco-editor",
/monaco-editor\/.*/,
"@guolao/vue-monaco-editor",
/three\/examples\/jsm\/libs\/draco\/draco_(en|de)coder\.js/,
]
: [],
},
},
worker: {
format: "es", // Use ES modules for workers (IIFE is not supported with code-splitting)
},
define: {
__APP_NAME__: JSON.stringify(name),
__APP_VERSION__: JSON.stringify(version),
__APP_GIT_SHA__: JSON.stringify(getGitInfo("git rev-parse HEAD", "unknown")),
__APP_GIT_DIRTY__: JSON.stringify(getGitInfo("git diff --quiet || echo dirty", "")),
__YACV_SMALL_BUILD__: JSON.stringify(wantsSmallBuild),
},
});
function viteStaticCopyPyodide() {
// @ts-ignore
const pyodideDir = dirname(fileURLToPath(import.meta.resolve("pyodide")));
const pyodideInc = [];
for (let glob of ["**", "!**/*.{md,html}", "!**/*.d.ts", "!**/*.whl", "!**/node_modules"]) {
pyodideInc.push(join(pyodideDir, glob));
}
return viteStaticCopy({
targets: wantsSmallBuild
? []
: [
{
src: pyodideInc,
dest: "pyodide-v" + pyodideVersion, // It would be better to use hashed names instead of folder...
},
],
});
}