Repository navigation
Expand file tree
/
Copy pathvite.web.config.ts
More file actions
63 lines (62 loc) · 3 KB
/
Copy pathvite.web.config.ts
File metadata and controls
63 lines (62 loc) · 3 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
import { defineConfig } from 'vite'
import pkg from './package.json'
/**
* The deployable site, as published to amos.bitplane.net.
*
* `vite.config.ts` is a *library* build (src/index.ts -> dist/amos-ts.js) for
* consumers importing the runtime. This one is the app build: the standalone
* player, emitted to dist-web/.
*
* `base: './'` matters more than it looks. The same build is published to
* three places — the site root, /v/<x.y.z>/ and /v/latest/ — so every asset
* reference has to be relative to the page rather than to the server root.
* With the default absolute base, a copy under /v/0.3.0/ would ask for
* /assets/... and get the root build's files, which is the sort of bug that
* only shows up after a version has been pinned for a month.
*/
export default defineConfig({
// stamped into the bundle so a page can say which build it is running,
// which is the only way to notice a CDN still serving an old /v/latest/
define: {
__AMOS_VERSION__: JSON.stringify(pkg.version),
// Where the disk library is served from, and an ABSOLUTE path where
// everything else here is relative. The library is published once, by
// bitplane/amos-library's own job; the bundle is published three times.
// A relative 'library/' would have the copy under /v/0.9.1/ asking for
// /v/0.9.1/library/index.json, which is not there and never will be.
__AMOS_LIBRARY__: JSON.stringify('/library/'),
},
base: './',
build: {
outDir: 'dist-web',
emptyOutDir: true,
target: 'es2022',
// No sourcemap in the published site. It is 2.9 MB against the bundle's
// 827 kB, and every version is kept forever under /v/, so shipping it
// would grow the site repo four times faster for something almost nobody
// fetches. Each release is reproducible from its tag — check out v0.3.0
// and `npm run build:web` with sourcemap on to debug that exact build.
sourcemap: false,
// One 827 kB chunk is the whole interpreter and runtime with no
// dependencies behind it, and a single file is the easiest thing to
// embed. Splitting it would trade that for parallel fetches we do not
// need, so the warning is turned off rather than worked around.
chunkSizeWarningLimit: 1024,
rollupOptions: {
output: {
// No content hash in the filename. Hashing exists to bust caches
// when a URL's contents change, and here they never do: every
// version lives at its own immutable path, so the path IS the cache
// key. Hashing on top of that would only mean /v/latest/ collecting
// a new orphaned bundle on every release, and it would deny anyone
// embedding the player a URL they can predict and write down.
//
// This is the standalone page's bundle; the library an embedder
// imports is assets/amos-player.js, built by vite.lib.config.ts.
entryFileNames: 'assets/standalone.js',
chunkFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name][extname]',
},
},
},
})