Appearance
Building Assets
Introduction
A Vue theme is built with Vite; a Blade theme has nothing to build. Every Vue theme gets a build of its own, public/, with its own manifest — that is what lets an administrator switch between built themes without a rebuild.
kitloom/ brings what the build needs, in vendor/:
| File | What it is |
|---|---|
index. | The Vite plugin, kitloom, and the helpers active, theme, theme and builds. |
page- | The plugin that writes a TypeScript theme's resources/. kitloom includes it. |
templates. | The plugin that writes kitloom-. kitloom includes it. |
build- | A script that builds every installed Vue and React theme, one after another: npm run build. |
The Vite config
js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
import react from '@vitejs/plugin-react';
import kitloomTheme, { activeTheme, buildsWithVite, themeEntry } from './vendor/kitloom/site-inertia/vite/index.js';
export default defineConfig(({ command }) => {
// `npm run build` names each theme it builds; `npm run dev` serves the one the site has active.
const theme = process.env.KITLOOM_BUILD_THEME || activeTheme();
// No theme, or a Blade one: nothing to build or serve.
if (!buildsWithVite(theme)) {
console.info('Vite has nothing to serve.');
process.exit(0);
}
if (command === 'serve') {
console.info(`Serving the ${theme} theme, the site's active one. After switching themes, start the dev server again.`);
}
return {
plugins: [
laravel({
input: [themeEntry(theme)],
buildDirectory: `build-${theme}`,
refresh: true,
}),
...kitloomTheme({ theme }),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
// A React theme's components; a Vue theme has none.
react({ include: /\.[jt]sx$/ }),
],
resolve: {
preserveSymlinks: true,
},
server: {
watch: {
ignored: ['**/storage/framework/views/**'],
},
},
};
});One run of Vite builds one theme: the one KITLOOM_ names (build- sets it, once per theme), or else the theme the site has active — active asks the site itself, php artisan site:, so the dev server serves what Appearance → Themes chose. . names no theme. With no theme, or a Blade theme, there is nothing to build: Vite says so and stops without an error, so composer run dev keeps the server, the queue and the logs going. A theme that is not installed is an error, and so is a site whose database does not answer: the active theme is not known then.
What the plugin does
| Export | Does |
|---|---|
active | The site's active theme, from php artisan site: (PHP as $PHP, else php); '' for none. Throws, with PHP's reason, when PHP or the database does not answer. |
theme | Finds the theme's directory, relative to the application root: themes/ when that folder exists, otherwise the package whose composer. declares the theme in extra. (read from vendor/). Throws when neither has it. |
builds | Whether there is a build to make: a Vue or React theme, with resources/. False for no theme and for a Blade theme; throws, as theme does, for a theme that is not installed. |
theme | The theme's entry script for laravel-'s input: vendor/. A theme without app. gets app., app. or app., the first it has. |
kitloom (default) | Three plugins, so it is spread into the list. The first makes @ the theme's resources/ — import Site. The second, kitloom-, writes resources/ when the build starts, for a theme written in TypeScript — with the theme's own parts even when it is not the active one, and a loose type ({ [key:) for each part it reads of a module the site does not have, so a theme compiles on any site. The third, kitloom-, on vite build only, writes kitloom-. |
kitloom-templates.json
The build writes kitloom- next to the manifest: the names of the theme's templates, from resources/ — single- is single-, templates/ is templates/.
text
public/build-Portfolio/
├── assets/
├── manifest.json
└── kitloom-templates.jsonThe server reads it twice:
- to pick the first template of the hierarchy the build has — a template added after the last build is not used until the next one, so the browser is never sent a component it does not have;
- to tell whether the theme is built — a Vue theme without the file is Not built yet on the Themes screen and cannot be activated.
When the active Vue theme renders a page, the site points @vite at that theme's build directory and gives the root view $theme, so @vite([$theme loads the active theme's build.
Building every theme
json
{
"scripts": {
"dev": "vite",
"build": "node vendor/kitloom/site-inertia/vite/build-themes.js",
"build:themes": "npm run build"
}
}build- collects the themes the way theme finds them — folders under themes/ and packages that declare extra. — and runs npx vite build with KITLOOM_ set to each one that has resources/, the active theme or not: a switch in the admin then needs no build. Blade themes are skipped. It takes no arguments; one theme is built by hand with:
bash
KITLOOM_BUILD_THEME=Studio npx vite buildRun npm run build on deploy. Keep the builds out of Git: / in ..
The dev server
bash
npm run devThe dev server serves the site's active theme, which it asks the site for when it starts: after a switch in the admin, start it again. While it runs (public/ exists), every Vue theme counts as built, and templates are looked up as files in resources/, so a new template is used at once.
Images and fonts
What the theme's CSS and JavaScript import — url('../, import logo from '@/ — goes through Vite into the theme's build, public/, with hashed names.
transform in the Vue plugin leaves absolute URLs in templates alone: <img src="/ stays as it is and is served from public/. Relative ones (./) are imported by Vite as above.
Symlinked packages
When theme packages come from a Composer path repository, vendor/ is a symlink to a directory outside the application. resolve. keeps Vite on the vendor/ path:
- the manifest's keys are
vendor/paths, the same entry the server gives… @vite; - the theme's imports (
vue,@inertiajs/,vue3 axios) are resolved from the application'snode_, not from the package's real directory.modules
A theme installed from a regular Composer repository is a plain directory, and the option changes nothing.
Changing the paths
The paths the server expects are in config/ (php artisan vendor:):
| Key | Default | Meaning |
|---|---|---|
build_ | build- | The build directory under public/; {theme} is replaced by the theme's name. |
entry | resources/ | The entry script, inside the theme. |
templates | resources/ | The templates directory, inside the theme. |
The Vite config has to agree: build for the first, theme for the second. The plugin always reads templates from resources/.
Blade themes
A Blade theme is drawn on the server and has no build. A theme that wants compiled CSS builds it inside its own package and ships the result: kitloom/ compiles its Tailwind CSS with npm run build in the package into resources/, commits it, and inlines it into its layout — the site runs no Node step for it.