extract shared theme CSS into standalone bundle
Move the 3 theme layer imports (primitives, layer2-attributes, semantic) out of admin.css and shop.css into a new theme.css bundle loaded by all root layouts. Eliminates 28 KB of duplication on admin pages where both admin.css and shop.css were each embedding the same theme CSS. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
40b9e80516
commit
3c9a428d09
@ -3,11 +3,6 @@
|
|||||||
/* Reset */
|
/* Reset */
|
||||||
@import "./admin/reset.css";
|
@import "./admin/reset.css";
|
||||||
|
|
||||||
/* Theme CSS layers (used by theme editor preview) */
|
|
||||||
@import "./theme-primitives.css";
|
|
||||||
@import "./theme-layer2-attributes.css";
|
|
||||||
@import "./theme-semantic.css";
|
|
||||||
|
|
||||||
/* Admin components, layout, icons, transitions */
|
/* Admin components, layout, icons, transitions */
|
||||||
@import "./admin/components.css";
|
@import "./admin/components.css";
|
||||||
@import "./admin/layout.css";
|
@import "./admin/layout.css";
|
||||||
|
|||||||
@ -5,13 +5,6 @@
|
|||||||
|
|
||||||
@import "./shop/reset.css";
|
@import "./shop/reset.css";
|
||||||
|
|
||||||
/* Theme CSS — unlayered so it overrides component layers (intentional).
|
|
||||||
Primitives set CSS custom properties, layer2 sets theme-aware rules,
|
|
||||||
semantic sets base styles on .themed containers. */
|
|
||||||
@import "./theme-primitives.css";
|
|
||||||
@import "./theme-layer2-attributes.css";
|
|
||||||
@import "./theme-semantic.css";
|
|
||||||
|
|
||||||
@import "./shop/components.css";
|
@import "./shop/components.css";
|
||||||
@import "./shop/layout.css";
|
@import "./shop/layout.css";
|
||||||
@import "./shop/utilities.css";
|
@import "./shop/utilities.css";
|
||||||
|
|||||||
6
assets/css/theme.css
Normal file
6
assets/css/theme.css
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/* Theme design tokens — shared by admin and shop CSS bundles.
|
||||||
|
Loaded separately so the browser caches it once for all page types. */
|
||||||
|
|
||||||
|
@import "./theme-primitives.css";
|
||||||
|
@import "./theme-layer2-attributes.css";
|
||||||
|
@import "./theme-semantic.css";
|
||||||
@ -61,6 +61,10 @@ config :esbuild,
|
|||||||
berrypod_admin_css: [
|
berrypod_admin_css: [
|
||||||
args: ~w(css/admin.css --bundle --outdir=../priv/static/assets/css),
|
args: ~w(css/admin.css --bundle --outdir=../priv/static/assets/css),
|
||||||
cd: Path.expand("../assets", __DIR__)
|
cd: Path.expand("../assets", __DIR__)
|
||||||
|
],
|
||||||
|
berrypod_theme_css: [
|
||||||
|
args: ~w(css/theme.css --bundle --outdir=../priv/static/assets/css),
|
||||||
|
cd: Path.expand("../assets", __DIR__)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Configures Elixir's Logger
|
# Configures Elixir's Logger
|
||||||
|
|||||||
@ -35,7 +35,9 @@ config :berrypod, BerrypodWeb.Endpoint,
|
|||||||
esbuild_shop_css:
|
esbuild_shop_css:
|
||||||
{Esbuild, :install_and_run, [:berrypod_shop_css, ~w(--sourcemap=inline --watch)]},
|
{Esbuild, :install_and_run, [:berrypod_shop_css, ~w(--sourcemap=inline --watch)]},
|
||||||
esbuild_admin_css:
|
esbuild_admin_css:
|
||||||
{Esbuild, :install_and_run, [:berrypod_admin_css, ~w(--sourcemap=inline --watch)]}
|
{Esbuild, :install_and_run, [:berrypod_admin_css, ~w(--sourcemap=inline --watch)]},
|
||||||
|
esbuild_theme_css:
|
||||||
|
{Esbuild, :install_and_run, [:berrypod_theme_css, ~w(--sourcemap=inline --watch)]}
|
||||||
]
|
]
|
||||||
|
|
||||||
# ## SSL Support
|
# ## SSL Support
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
<style>
|
<style>
|
||||||
@layer properties, reset, primitives, tokens, theme, base, components, layout, admin, utilities, overrides;
|
@layer properties, reset, primitives, tokens, theme, base, components, layout, admin, utilities, overrides;
|
||||||
</style>
|
</style>
|
||||||
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/theme.css"} />
|
||||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
||||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/shop.css"} />
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/shop.css"} />
|
||||||
<!-- Generated theme CSS with @font-face declarations -->
|
<!-- Generated theme CSS with @font-face declarations -->
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
<style>
|
<style>
|
||||||
@layer properties, reset, primitives, tokens, theme, base, components, layout, admin, utilities, overrides;
|
@layer properties, reset, primitives, tokens, theme, base, components, layout, admin, utilities, overrides;
|
||||||
</style>
|
</style>
|
||||||
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/theme.css"} />
|
||||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
||||||
<!-- Generated theme CSS with @font-face declarations -->
|
<!-- Generated theme CSS with @font-face declarations -->
|
||||||
<style id="theme-css">
|
<style id="theme-css">
|
||||||
|
|||||||
@ -62,6 +62,7 @@
|
|||||||
<style>
|
<style>
|
||||||
@layer properties, reset, primitives, tokens, theme, base, components, layout, utilities, overrides;
|
@layer properties, reset, primitives, tokens, theme, base, components, layout, utilities, overrides;
|
||||||
</style>
|
</style>
|
||||||
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/theme.css"} />
|
||||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/shop.css"} />
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/shop.css"} />
|
||||||
<%= if assigns[:current_scope] && @current_scope.user do %>
|
<%= if assigns[:current_scope] && @current_scope.user do %>
|
||||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
||||||
|
|||||||
4
mix.exs
4
mix.exs
@ -100,12 +100,14 @@ defmodule Berrypod.MixProject do
|
|||||||
"compile",
|
"compile",
|
||||||
"esbuild berrypod",
|
"esbuild berrypod",
|
||||||
"esbuild berrypod_shop_css",
|
"esbuild berrypod_shop_css",
|
||||||
"esbuild berrypod_admin_css"
|
"esbuild berrypod_admin_css",
|
||||||
|
"esbuild berrypod_theme_css"
|
||||||
],
|
],
|
||||||
"assets.deploy": [
|
"assets.deploy": [
|
||||||
"esbuild berrypod --minify",
|
"esbuild berrypod --minify",
|
||||||
"esbuild berrypod_shop_css --minify",
|
"esbuild berrypod_shop_css --minify",
|
||||||
"esbuild berrypod_admin_css --minify",
|
"esbuild berrypod_admin_css --minify",
|
||||||
|
"esbuild berrypod_theme_css --minify",
|
||||||
"phx.digest"
|
"phx.digest"
|
||||||
],
|
],
|
||||||
precommit: ["compile --warning-as-errors", "deps.unlock --unused", "format", "test"],
|
precommit: ["compile --warning-as-errors", "deps.unlock --unused", "format", "test"],
|
||||||
|
|||||||
@ -90,11 +90,11 @@ defmodule BerrypodWeb.ThemeCSSConsistencyTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "CSS file structure" do
|
describe "CSS file structure" do
|
||||||
test "admin.css imports shared theme layers" do
|
test "theme.css imports shared theme layers" do
|
||||||
css_path = Path.join([File.cwd!(), "assets", "css", "admin.css"])
|
css_path = Path.join([File.cwd!(), "assets", "css", "theme.css"])
|
||||||
css_content = File.read!(css_path)
|
css_content = File.read!(css_path)
|
||||||
|
|
||||||
# Admin imports the shared theme layers so .themed resolves all tokens
|
# Theme bundle imports all three shared layers
|
||||||
assert css_content =~ "theme-primitives.css"
|
assert css_content =~ "theme-primitives.css"
|
||||||
assert css_content =~ "theme-layer2-attributes.css"
|
assert css_content =~ "theme-layer2-attributes.css"
|
||||||
assert css_content =~ "theme-semantic.css"
|
assert css_content =~ "theme-semantic.css"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user