-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
61 lines (60 loc) · 3.1 KB
/
Copy pathvite.config.ts
File metadata and controls
61 lines (60 loc) · 3.1 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { fileURLToPath, URL } from "node:url";
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) },
},
// Font parsing is CPU-heavy; keep the worker format ESM so we can move it off
// the main thread without a bundling step.
worker: { format: "es" },
/*
* No sourcemaps in the build that ships. They were 11 MB of the 15 MB output
* and they publish the full source of `src/ui/`, which is not ours to
* publish -- see NOTICE.md. Turn this back on locally when a production-only
* bug needs reading -- `MAPS=1 npm run build` -- rather than leaving it on for
* everyone.
*/
/*
* No manual chunking, and none is needed to keep the drawing engine off the
* first screen.
*
* Naming `src/forge` a chunk was always the wrong tool: the entry imported it
* with a static import of some dozens of bindings, so index.html preloaded
* the chunk and the same bytes arrived before the first screen out of a
* second file. What moved it was removing the imports, one edge at a time --
* the palette catalogue, the project format, the four mode panels, the three
* document-to-typeface handlers and the three components that wanted a family
* name or a greyed-out undo button. `state/drawn.ts` is what most of them ask
* instead.
*
* The last edge was font/transform.ts taking `shapedInk` from forge/layers,
* on the synchronous path that resolves an outline -- which every view and
* the store call, and which has nowhere in it to await a download. This note
* used to say that moving it meant making that path async, and that this
* reached every drawing in the application.
*
* It did not. The shaping already answered "not yet" for a living: both
* layers are boolean geometry, boolean geometry is `paper`, and `paper` is
* fetched in the background -- so a cut letter has always been drawn plain
* until the library lands and drawn again when it does. `forge/layers.ts` is
* now a synchronous gate that asks the same question about one more module,
* and the redraw that was already waiting for one waits for both. That file
* has the argument.
*
* What is left in the first load of `src/forge` is that gate, at 0.8 kB.
*
* Measured with the script in the pull requests that did it: the first load
* -- the entry chunk plus everything it statically imports -- went from
* 1195 kB (379 kB gzipped) to 781 kB (257 kB) by removing the imports, and
* to 751 kB (246 kB) by gating the shaping. That last step is worth eleven
* kilobytes gzipped rather than the twenty-three this note used to claim:
* the old figure was the raw size of the modules, and most of what they
* reach is shared with chunks that were staying anyway. If you are about to
* add an import to something that renders on the first screen, check what it
* reaches before you do.
*/
build: { target: "es2022", sourcemap: process.env.MAPS === "1" },
});