Build the Workbench's package CSS apart from Tailwind
Plan step 37 review. @tailwindcss/vite inlines the imports of an entry that uses Tailwind without Vite's skipDuplicates, so with all.css beside @import 'tailwindcss' every shared component stylesheet repeated later in the cascade (231 repeated rules; button.css's hover and disabled rules thirteen times), and every browser test ran against an order no application gets. workbench/resources/css/package.css now holds all.css and the scheme in an entry Tailwind never touches, and app.css keeps Tailwind for the showcase's classes. The built package CSS repeats no rule, and the Workbench's CSS shrinks from 559 to 406 KB. Both entries open with the same layer statement, properties first, because Tailwind hoists that layer to the top of its output; the order is the one the single entry had, whichever the page links first. The showcase's Vite config, vite.config.js and the error page test's probe manifest name the new entry. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
co-authored by
Claude Opus 5
parent
eda16ba727
commit
3854f4321c
@@ -97,6 +97,7 @@ it('lets the application\'s own error view win', function () {
|
||||
it('loads the application\'s Vite entries', function () {
|
||||
File::ensureDirectoryExists($this->temporary.'/build');
|
||||
File::put($this->temporary.'/build/manifest.json', json_encode([
|
||||
'workbench/resources/css/package.css' => ['file' => 'assets/package-probe.css', 'src' => 'workbench/resources/css/package.css', 'isEntry' => true],
|
||||
'workbench/resources/css/app.css' => ['file' => 'assets/app-probe.css', 'src' => 'workbench/resources/css/app.css', 'isEntry' => true],
|
||||
'workbench/resources/js/app.js' => ['file' => 'assets/app-probe.js', 'src' => 'workbench/resources/js/app.js', 'isEntry' => true],
|
||||
]));
|
||||
@@ -106,6 +107,7 @@ it('loads the application\'s Vite entries', function () {
|
||||
|
||||
$this->get('/abort/404')
|
||||
->assertNotFound()
|
||||
->assertSee('build/assets/package-probe.css', false)
|
||||
->assertSee('build/assets/app-probe.css', false)
|
||||
->assertSee('build/assets/app-probe.js', false)
|
||||
->assertDontSee('data-md-error-fallback', false);
|
||||
|
||||
@@ -630,23 +630,35 @@ it('draws the interaction classes as the utilities the Tailwind components still
|
||||
->and(stylesheetBlock($interaction, '.md-touch-target'))->toContain('min-width: var(--md-sys-measurement-space600);');
|
||||
});
|
||||
|
||||
it('declares the material layers in the Workbench between Tailwind\'s preflight and its utilities', function () {
|
||||
it('builds the package in a Workbench entry of its own, with the material layers between Tailwind\'s preflight and its utilities', function () {
|
||||
$package = stylesheetWithoutComments(File::get(__DIR__.'/../../workbench/resources/css/package.css'));
|
||||
$app = stylesheetWithoutComments(File::get(__DIR__.'/../../workbench/resources/css/app.css'));
|
||||
|
||||
// The first statement orders the layers: above preflight, whose `* { padding: 0 }` would
|
||||
// otherwise beat a rewritten component's padding, and below the utilities.
|
||||
expect(trim($app))->toStartWith('@layer theme, base, material, components, utilities;');
|
||||
// Both entries open by ordering the layers, so the order holds whichever the page links first:
|
||||
// above preflight, whose `* { padding: 0 }` would otherwise beat a component's padding, and
|
||||
// below the utilities.
|
||||
foreach (['package.css' => $package, 'app.css' => $app] as $name => $css) {
|
||||
expect(trim($css))->toStartWith('@layer properties, theme, base, material, components, utilities;', $name);
|
||||
}
|
||||
|
||||
$all = strpos($app, "@import '../../../resources/css/all.css';");
|
||||
$tailwind = strpos($app, "@import 'tailwindcss'");
|
||||
$components = strpos($app, "@import '../../../resources/css/tailwind.css';");
|
||||
|
||||
expect($all)->toBeInt()
|
||||
->and($tailwind)->toBeGreaterThan($all)
|
||||
->and($components)->toBeGreaterThan($tailwind)
|
||||
// material.css declared the tokens a second time; components.css and layout.css are the
|
||||
// interim lists all.css replaced.
|
||||
->and($app)->not->toContain('material.css')
|
||||
->not->toContain("resources/css/components.css'")
|
||||
->not->toContain("resources/css/layout.css'");
|
||||
// The package's CSS never shares an entry with Tailwind: `@tailwindcss/vite` inlines the
|
||||
// imports of an entry that uses Tailwind without deduplicating them, so every shared component
|
||||
// stylesheet would repeat later in the cascade instead of landing once, as it does for an
|
||||
// application (StylesheetsBundleTest.php pins that against a real Vite build).
|
||||
expect($package)->toContain("@import '../../../resources/css/all.css';")
|
||||
->toContain("@import './material-scheme.css';")
|
||||
->not->toContain('tailwind')
|
||||
->not->toMatch('/@(?:source|theme|utility|variant|custom-variant|apply)\b/')
|
||||
->and($app)->toContain("@import 'tailwindcss'")
|
||||
->toContain("@import '../../../resources/css/tailwind.css';")
|
||||
->not->toContain('all.css')
|
||||
->not->toContain('foundation.css')
|
||||
->not->toContain('/components/')
|
||||
->not->toContain('material-scheme.css')
|
||||
->and(File::get(__DIR__.'/../../vite.config.js'))->toContain("'workbench/resources/css/package.css', 'workbench/resources/css/app.css'")
|
||||
->and(config('livewire-material.showcase.vite'))->toBe([
|
||||
'workbench/resources/css/package.css',
|
||||
'workbench/resources/css/app.css',
|
||||
'workbench/resources/js/app.js',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user