Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ yarn-error.log*

# Sourcemaps from pre-built utility bundles (issue #57): don't recommit them
static/utility-apps/**/*.map

# Generated by ANALYZE=1 builds
bundle-report.html
60 changes: 60 additions & 0 deletions dev-plans/bundle-audit-2026-07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Bundle Audit — July 2026 (issue #99)

Run `ANALYZE=1 npm run build` to regenerate the interactive report at
`build/bundle-report.html` (webpack-bundle-analyzer, client bundle only).

## Headline result

The micro-app migrations (#93/#94/#95) already achieved the audit's main goal:
**no WASM, 3D, or document library ships on the critical path.** Every page
loads the same two files first:

| File | Parsed size | Contents |
|---|---|---|
| `main.<hash>.js` | 633 KB | react-dom (174 KB), prism-react-renderer + prismjs (109 KB), Docusaurus theme/runtime (~140 KB), lunr + language stemmers (71 KB, offline search), mark.js (17 KB), site code incl. the `en` dictionary (33 KB) |
| `runtime~main.<hash>.js` | 9 KB | webpack runtime |

Everything in `main` is framework or deliberately-global functionality
(search, syntax highlighting, theme). There is no obvious low-effort cut left:
the next meaningful step would be swapping search or highlighting strategies,
which trades UX for bytes.

## Heavy libraries — all verified lazy

| Chunk | Size | Contents | Loaded on |
|---|---|---|---|
| `7084.*` | 3.0 MB | rapier physics (2.2 MB) + three.js (698 KB) + react-three-fiber | Eco Sort game page only |
| `5741.*` | 743 KB | @mdx-js/mdx compiler + acorn + framer-motion | MDX post editor only |
| `3512.*` | 391 KB | jspdf | PDF-export tools only |
| `5527.*` | 262 KB | emoji-picker-react | comment editor interaction |
| locale chunks | ~15 KB each | `ru/ua/de/es/et` dictionaries | on language switch (only `en` is in `main`) |

Supabase is dynamically imported by the lazy client facade
(`src/lib/supabaseClient.ts`) and does not appear in `main`.

## Changes made in this audit

1. **Removed dead dependencies `replicad` and `replicad-opencascadejs`** —
zero imports remained in `src/` after the CAD tools moved to standalone
apps. Shrinks installs/CI by ~15 MB (the OpenCascade WASM binary alone is
~11 MB in node_modules); runtime bundles were never affected because
webpack only bundles imported modules.
2. **Removed the replicad WASM webpack config** (`asyncWebAssembly`,
`__filename` mocks, `fs/path/crypto` fallbacks) — nothing in the site
bundle imports WASM anymore. Verified by a clean production build.
3. **Committed the analyzer tooling** (`ANALYZE=1` flag in the webpack
plugin) so future audits are a one-liner.

## Acceptance criteria mapping

- *Bundle analysis report committed or documented* — this file + reproducible
`ANALYZE=1` build.
- *No WASM/3D library loaded on the landing or docs pages* — verified: the
only render-path JS is `main` + `runtime` (table above); three/rapier live
exclusively in the Eco Sort chunk.
- *Measurable reduction in first-load JS for non-tool pages* — the big
reduction was delivered by the migrations this audit verified (the last
in-bundle CAD tool previously pulled replicad/OpenCascade context into
shared chunks); this pass removes the leftover dependency and config debt
and establishes the measurement baseline (642 KB total first-load) to hold
the line against regressions.
40 changes: 19 additions & 21 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dotenv.config({path: './.env.local'});
import {themes as prismThemes} from 'prism-react-renderer';
import type {Config} from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';

const config: Config = {
title: 'CAD AutoScript',
Expand Down Expand Up @@ -49,29 +50,26 @@ const config: Config = {
},
clientModules: ['./src/clientModules/errorReporting.ts'],
plugins: [
async function myPlugin(_context, _options) {
async function siteWebpackPlugin(_context, _options) {
return {
name: 'docusaurus-replicad-config',
configureWebpack(_config, _isServer) {
name: 'site-webpack-config',
configureWebpack(_config, isServer) {
// ANALYZE=1 npm run build → writes build/bundle-report.html (client bundle).
// The replicad/OpenCascade WASM webpack config that used to live here
// was removed with the last in-bundle CAD tool (issues #93/#94/#99):
// every WASM consumer now runs as a standalone utility app.
const analyzerPlugins =
process.env.ANALYZE && !isServer
? [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '../bundle-report.html',
openAnalyzer: false,
}),
]
Comment on lines +60 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are two issues with the current webpack bundle analyzer configuration:

  1. Environment Variable Check: process.env.ANALYZE is a string. If a user runs the build with ANALYZE=false or ANALYZE=0, it will still evaluate to truthy in JavaScript, causing the analyzer to run unexpectedly. It is safer to explicitly check for 'true' or '1'.
  2. Report Filename Path: Docusaurus sets the webpack output.path to the build directory. Using ../bundle-report.html will write the report to the project root (one level above build), polluting the repository. Changing it to 'bundle-report.html' ensures it is written inside the build directory as documented in dev-plans/bundle-audit-2026-07.md.
Suggested change
// every WASM consumer now runs as a standalone utility app.
const analyzerPlugins =
process.env.ANALYZE && !isServer
? [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '../bundle-report.html',
openAnalyzer: false,
}),
]
const analyzerPlugins =
(process.env.ANALYZE === 'true' || process.env.ANALYZE === '1') && !isServer
? [
new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)({
analyzerMode: 'static',
reportFilename: 'bundle-report.html',
openAnalyzer: false,
}),
]
: [];

: [];
return {
// replicad-opencascadejs requires async-WebAssembly streaming.
experiments: {
asyncWebAssembly: true,
},
// Vendor wasm bindings reference __filename / __dirname. webpack 5
// defaults to 'warn-mock', which mocks them AND emits a warning per
// locale build. 'mock' keeps the same runtime behaviour silently.
node: {
__filename: 'mock',
__dirname: 'mock',
},
resolve: {
fallback: {
crypto: false,
fs: false,
path: false,
},
},
plugins: analyzerPlugins,
};
},
};
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.1",
"remark-mdx-frontmatter": "^5.2.0",
"replicad": "^0.20.5",
"replicad-opencascadejs": "^0.20.2",
"three": "^0.182.0",
"three-stdlib": "2.36.1",
"uuid": "^13.0.1",
Expand All @@ -86,7 +84,8 @@
"sharp": "^0.34.5",
"tailwindcss": "^4.2.1",
"typescript": "~5.6.2",
"typescript-eslint": "^8.64.0"
"typescript-eslint": "^8.64.0",
"webpack-bundle-analyzer": "^5.3.1"
},
"browserslist": {
"production": [
Expand Down
Loading
Loading