-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
85 lines (79 loc) · 2.35 KB
/
vite.config.ts
File metadata and controls
85 lines (79 loc) · 2.35 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
import path from "path";
import { injectIWER } from "@iwsdk/vite-plugin-iwer";
import { compileUIKit } from "@iwsdk/vite-plugin-uikitml";
import fs from "fs";
import { defineConfig, type Plugin } from "vite";
// Uncomment the import below and add optimizeGLTF() to the plugins array
// when you place GLTF/GLB files in public/gltf/:
// import { optimizeGLTF } from "@iwsdk/vite-plugin-gltf-optimizer";
const threePkg = path.resolve(__dirname, "node_modules/three");
/**
* Redirect IWSDK's bundled super-three@0.177.0 imports to the project's
* single Three.js instance, preventing duplicate Three.js modules and the
* resulting "Can not resolve #include <splatDefines>" shader error.
*/
function deduplicateThree(): Plugin {
const bundledThreeRe =
/node_modules\/@iwsdk\/core\/dist\/node_modules\/\.pnpm\/super-three@[\d.]+\/node_modules\/super-three\/(.*)/;
return {
name: "deduplicate-three",
enforce: "pre",
resolveId(source, importer) {
if (!importer) return null;
const resolved = source.startsWith(".")
? path.resolve(path.dirname(importer), source)
: null;
const target = resolved ?? source;
const match = target.match(bundledThreeRe);
if (match) {
return path.join(threePkg, match[1]);
}
return null;
},
};
}
export default defineConfig({
plugins: [
deduplicateThree(),
// mkcert() replaced by manual certs below
injectIWER({
device: "metaQuest3",
activation: "localhost",
verbose: true,
}),
compileUIKit({ sourceDir: "ui", outputDir: "public/ui", verbose: true }),
],
resolve: {
alias: {
three: threePkg,
},
dedupe: ["three"],
},
server: {
host: "0.0.0.0",
port: 8081,
open: true,
headers: {
"Cache-Control": "no-store",
},
https: fs.existsSync(path.resolve(__dirname, ".key.pem"))
? {
key: fs.readFileSync(path.resolve(__dirname, ".key.pem")),
cert: fs.readFileSync(path.resolve(__dirname, ".cert.pem")),
}
: undefined,
},
build: {
outDir: "dist",
sourcemap: process.env.NODE_ENV !== "production",
target: "esnext",
rollupOptions: { input: "./index.html" },
},
esbuild: { target: "esnext" },
optimizeDeps: {
exclude: ["@babylonjs/havok"],
esbuildOptions: { target: "esnext" },
},
publicDir: "public",
base: "./",
});