[Matrix] Vite Build System — bundle Three.js, remove CDN dependency #61
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What & Why
The Matrix currently loads Three.js and all addons from esm.sh CDN at runtime. This means the app cannot load offline, the CDN is a hard runtime dependency, and there is no asset optimization, tree-shaking, or source maps. The iPad PWA use case requires a proper build — and this is the prerequisite for the service worker / PWA manifest task.
Done looks like
npm run buildinthe-matrixrepo produces a workingdist/with all Three.js assets bundled locallynpm run devstarts a Vite dev server with hot reloadesm.shURLs remain in any source filepackage.jsonat0.171.0dist/andnode_modules/in.gitignoreOut of scope
Tasks
package.jsonwiththree@0.171.0as dep andviteas devDep. Adddev,build,previewscripts.esm.shCDN URLs injs/*.jswith bare specifier imports (import * as THREE from "three",import { OrbitControls } from "three/addons/controls/OrbitControls.js", etc.).<script type="importmap">or CDN<link>tags. Ensure<script type="module" src="./js/main.js">is the only entry point.vite.config.jsif needed for base path or alias config. Confirmnpm run buildoutputs todist/andnpm run previewserves it.node_modules/anddist/.Relevant files
the-matrix/index.htmlthe-matrix/js/main.jsthe-matrix/js/world.jsthe-matrix/js/agents.jsthe-matrix/js/websocket.jsAll requirements for this issue are already implemented on
main:package.jsonwiththree@0.171.0as dep,viteas devDep, anddev/build/previewscriptsnpm run buildproduces a workingdist/with all Three.js assets bundled locallynpm run devstarts Vite dev server with hot reloadesm.shURLs remain in any source file — all imports use bare specifiers (import * as THREE from "three")index.htmlhas noimportmap— single<script type="module" src="./js/main.js">entry pointdist/andnode_modules/in.gitignorevite.config.jsconfigured with build output, dev server proxy, and service worker generationThis issue can be closed as already complete.
PR created: #89
The Vite build system was already mostly in place on
main(bare specifier imports fromthree,package.jsonwiththree@0.171.0,vite.config.js,.gitignorewithdist/andnode_modules/). This PR:dist/from git — it was previously committed despite being in.gitignore; runninggit rm --cachedremoves it from version controlpackage-lock.json— regenerated after cleannpm installnpm run buildproduces a working bundleddist/with no CDN references.