-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
72 lines (69 loc) · 2.63 KB
/
Copy pathvite.config.ts
File metadata and controls
72 lines (69 loc) · 2.63 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
import { defineConfig } from "vite";
// output file names must be all lowercase: the name part is inlined into the
// pattern lowercased, and base36 hashes are lowercase alphanumeric only
const lowercase = (name: string) => name.toLowerCase().replaceAll(/[[\]]/g, "_");
const lowercaseNames = {
hashCharacters: "base36",
entryFileNames: (chunk: { name: string }) => `assets/${lowercase(chunk.name)}-[hash].js`,
chunkFileNames: (chunk: { name: string }) => `assets/${lowercase(chunk.name)}-[hash].js`,
assetFileNames: (asset: { names: string[] }) => {
const name = asset.names[0] ?? "asset";
const dot = name.lastIndexOf(".");
return `assets/${lowercase(dot > 0 ? name.slice(0, dot) : name)}-[hash][extname]`;
},
} as const;
export default defineConfig({
// Relative, so one build runs from any path: `/`, `/labs/node/`, a file:// tree. Vite emits
// asset URLs computed from `import.meta.url` instead of rooted at `/`, which is what lets the
// same dist be deployed twice at different depths. Anything the app fetches by hand has to go
// through `appUrl` (src/base.ts) to get the same treatment.
//
// This requires the page be served at a directory URL with a trailing slash (`/labs/node/`, not
// `/labs/node`) — relative URLs resolve against the *document*, so a missing slash drops a
// segment. Dev is unaffected: Vite forces base to `/` when serving.
base: "./",
server: {
proxy: {
// The relay endpoint is origin-gated and does not know `localhost`, so anonymous mode
// cannot be exercised under `pnpm dev` at all — it fails before the workspace boots.
// This forwards it under an origin the endpoint does recognize, which is the only thing
// it checks. Dev-only (Vite ignores `server` in a build), and reached by pointing
// `VITE_WISP_URL_ENDPOINT` at `/__wisp/`.
"/__wisp": {
target: "https://sensible-ship-8305.puter.work",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/__wisp\/?/, "/"),
headers: {
Origin: "https://developer.puter.com",
Referer: "https://developer.puter.com/labs/node/",
},
},
},
},
build: {
chunkSizeWarningLimit: Infinity,
rolldownOptions: {
checks: {
pluginTimings: false,
},
output: {
...lowercaseNames,
manualChunks: (id) => {
if (id.includes("monaco-editor")) {
return "monaco";
}
// A single prebuilt bundle with every command in it — npm ships no sources, so
// there is nothing to tree-shake. Its own chunk, so it is cached on its own.
if (id.includes("just-bash")) {
return "just-bash";
}
},
},
},
},
worker: {
rolldownOptions: {
output: lowercaseNames,
},
},
})