-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvite.config.ts
More file actions
70 lines (64 loc) · 1.75 KB
/
vite.config.ts
File metadata and controls
70 lines (64 loc) · 1.75 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
import fs from "fs";
import path from "path";
import react from "@vitejs/plugin-react";
import { defineConfig, Plugin } from "vite";
import glsl from "vite-plugin-glsl";
const staticFiles = new Map([
[
"/basis/basis_transcoder.js",
"node_modules/three/examples/jsm/libs/basis/basis_transcoder.js",
],
[
"/basis/basis_transcoder.wasm",
"node_modules/three/examples/jsm/libs/basis/basis_transcoder.wasm",
],
[
"/basis/basis_encoder.js",
"node_modules/ktx2-encoder/dist/basis/basis_encoder.js",
],
[
"/basis/basis_encoder.wasm",
"node_modules/ktx2-encoder/dist/basis/basis_encoder.wasm",
],
]);
const mimeTypes = new Map([
[".js", "application/javascript"],
[".wasm", "application/wasm"],
]);
function staticCopyPlugin(): Plugin {
return {
name: "static-copy",
configureServer(server) {
server.middlewares.use((req, res, next) => {
const src = staticFiles.get(req.url!);
if (!src) return next();
const mimeType =
mimeTypes.get(path.extname(src)) ?? "application/octet-stream";
res.setHeader("Content-Type", mimeType);
res.end(fs.readFileSync(path.resolve(__dirname, src)));
});
},
writeBundle() {
for (const [dest, src] of staticFiles) {
const destPath = path.resolve(__dirname, "dist", dest.slice(1));
fs.mkdirSync(path.dirname(destPath), { recursive: true });
fs.copyFileSync(path.resolve(__dirname, src), destPath);
}
},
};
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), glsl(), staticCopyPlugin()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
optimizeDeps: {
exclude: ["ktx2-encoder"],
},
worker: {
format: "es",
},
});