Skip to content

feat(css): migrate CSS build from webpack to Vite - #13326

Merged
RayBB merged 11 commits into
masterfrom
feat/vite-css-build
Aug 13, 2026
Merged

feat(css): migrate CSS build from webpack to Vite#13326
RayBB merged 11 commits into
masterfrom
feat/vite-css-build

Conversation

@RayBB

@RayBB RayBB commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Replaces webpack.config.css.js with vite-css.config.mjs, building the same 17 CSS entries with @import resolution, esbuild minification, and url() passthrough parity.

Speed Improvements :

Environment Before After Speedup
My (Fast) machine ~3s ~0.8s ~4Γ—
Jenkins tests ~40s ~8s ~5Γ—
  • Hoisted mid-file @imports to the top of affected CSS files (invalid per spec, silently dropped by Vite) β€” output verified byte-identical to webpack's
  • New repo-local stylelint rule ol/import-at-top (+ unit tests) so a regression fails npm run lint, not just the build
  • npm run watch now streams both webpack and Vite output; clearScreen: false stops Vite wiping the shared terminal
  • Dev/prod behavior gated on Vite mode instead of NODE_ENV; regression guards on the url passthrough now fail the build
  • Parity verified: identical /static/ references, selector sets, and gzip sizes (within 1KB) vs webpack; all bundlesize checks pass

As far as I can tell there are no regressions at all. The only weirdness is that we set this public directory to the root because we don't want them rewriting our urls since we don't bundle in images.

RayBB added 5 commits August 12, 2026 16:55
Replace webpack.config.css.js with vite-css.config.mjs for the CSS
build (17 entries, minified). Preserve url(/static/...) references via
a PostCSS Once-hook passthrough, and hoist all mid-file @imports to the
top (webpack output proven byte-identical before/after). Vite builds
~3.7x faster on host. Remove mini-css-extract-plugin,
css-minimizer-webpack-plugin, and glob deps; update docs.
Add a repo-local stylelint rule (ol/import-at-top) that flags any
@import after the first statement in a CSS file. The Vite build
silently drops mid-file @imports, so this alerts in CI (npm run lint),
the pre-commit stylelint hook, and editors. Registered in
.stylelintrc.json and covered by jest tests that run the real stylelint
CLI.
…build

Two pieces of custom code in vite-css.config.mjs turned out to be
unnecessary:

- @charset restoration: legacy.css's `@charset "utf-8";` was removed from
  source to silence postcss-import warnings, so the ~45-line import-graph
  walk + closeBundle re-add that restored it into outputs was pure
  byte-parity chasing. Vite natively strips the declaration; it's
  meaningless for HTTP-served CSS (charset comes from headers, utf-8 is
  the default). Output now simply lacks it (~16B smaller on the 7
  legacy-importing files).

- removeCompanionJsChunks: Vite 8 omits the empty JS stub chunk for
  pure-CSS entries natively, making the plugin dead code.

A closeBundle regression guard now warns if stray .js files appear in the
CSS output (a future Vite upgrade could stop omitting them), matching the
existing data:image/__OL__ guard philosophy.

Docs updated in docs/ai/css-vite-migration.md. Build verified: `make css`
clean, /static/ url parity vs webpack unchanged, no data URIs or
placeholders, gzip ~16B smaller, eslint/stylelint clean, jest 5/5.
@RayBB
RayBB requested a review from lokesh August 13, 2026 02:29

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Went through the site on testing a few times and not seeing any CSS issues. Love the speed improvements! Approach looks good to me.

Comment thread docs/ai/css-vite-migration.md Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think there's a lot of value in committing this historical doc here? The docs in css.md are sufficient.

@RayBB
RayBB merged commit fcada7c into master Aug 13, 2026
9 checks passed
@RayBB
RayBB deleted the feat/vite-css-build branch August 13, 2026 18:11
@cdrini

cdrini commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Oh whoops sorry meant to just communicate it lgtm :D I think @lokesh should have a chance to provide feedback as well since he's assigned and more directly impacted by these changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants