Add Stylesheets::bundle(), a build-free CSS import resolver
Plan step 37: the showcase and the error page's fallback serve CSS without the application's Vite build, so nothing deduplicates their @imports for them the way Vite's bundled postcss-import does — a browser's native @import fetches every occurrence, it does not skip a file it already loaded. Stylesheets::bundle(array $files, ?string $base = null): string does in PHP what that build step does: it inlines every @import depth-first, each file once, first occurrence kept; leaves a bare specifier or an absolute URL untouched; rewrites a relative url() against $base (or, without one, against the directory of $files[0]); breaks a cycle instead of looping; throws naming the importer when an import is missing; and caches per resolved file list and mtime, with resetCache() for tests. tests/Feature/StylesheetsBundleTest.php covers bundle()'s own behaviour (dedup, url() rewriting, cycles, the missing-import exception, the cache) and, at the end, pins the Vite deduplication bundle() is modelled on against a real build — of all.css alone (tests/Fixtures/dedup.vite.config.mjs), whose docblock explains why: the Workbench's own entry still shares one file with @tailwindcss/vite until plan step 39 removes it, and that plugin bundles its whole reachable module graph itself, without the same dedup guarantee. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
a967cfcc2b
commit
792ec44d5e
@@ -0,0 +1,26 @@
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
// Builds resources/css/all.css alone, with no other plugin in the graph: it isolates Vite's own
|
||||
// bundled postcss-import, whose `skipDuplicates` option is the mechanism
|
||||
// docs/plans/material-3-alignment.md's "Tailwind's footprint" paragraph measured and
|
||||
// StylesheetsBundleTest.php pins against the real bundler — a stylesheet several files import
|
||||
// lands once, at its first position.
|
||||
//
|
||||
// The Workbench's own entry (vite.config.js) still shares one file with `@tailwindcss/vite` until
|
||||
// plan step 39 removes it, and that plugin bundles its whole reachable module graph itself,
|
||||
// independently of Vite's CSS pipeline; it does not carry the same `skipDuplicates` option, so a
|
||||
// shared component stylesheet currently lands once per import site there, not once overall. That
|
||||
// is a pre-existing limitation of mixing the two in one entry, not something plan step 37
|
||||
// introduces or can fix without moving Tailwind out of the Workbench's entry (step 39's job) — this
|
||||
// fixture is what actually exercises the claim being pinned, decoupled from it.
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: process.env.DEDUP_OUT_DIR,
|
||||
emptyOutDir: true,
|
||||
manifest: true,
|
||||
rollupOptions: {
|
||||
input: 'resources/css/all.css',
|
||||
},
|
||||
},
|
||||
logLevel: 'silent',
|
||||
});
|
||||
Reference in New Issue
Block a user