Set up Master CSS in Laravel
Guide to setting up Master CSS in your Laravel project.
Master CSS Runtime Rendering observes changes in DOM class names at browser runtime, generates corresponding CSS rules, and injects them into the running style sheet.
Fixed style cost
All features work out of the box with ~17KB transfer cost
Fully automatic
Capture any program-generated class names
CSS lifecycle
Generated on-demand and frees memory when not in use
Quick start
Clone the example
Copy-paste the following commands to quickly start using the example.
You can skip all installation steps.
npm create @master/css@rc project --example laravel-with-runtime-renderingcd project
Launch server
Run Laravel and Vite development servers by splitting two terminals.
php artisan serve
Installation
Create a project
If you don't have a Laravel project, create one first. It's recommended to refer to Installation - Laravel
composer create-project laravel/laravel example-app
Initialize configuration file
Run npm create @master/css@rc
to create a configuration file master.css.js.
npm create @master/css@rc
Install Master CSS
Install Master CSS into your project via package managers.
npm install @master/css-runtime@rc
Set up CSS runtime engine
Import master.css.js
config and initialize the runtime engine in your resources/js/app.js
file.
import './bootstrap'import { initCSSRuntime } from '@master/css-runtime'import config from 'master.css' initCSSRuntime(config)
Set up your view layout
Include the following in your resources/views/layouts/welcome.blade.php
:
- Import the entry by adding
@vite('resources/js/app.js')
- Add
display: none
to<html>
to avoid FOUC
<!DOCTYPE html><html style="display: none" lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> … @vite('resources/js/app.js') </head> …</html>
Launch server
Run Laravel and Vite development servers by splitting two terminals.
php artisan serve
Hello world!
Now style your first element using Master CSS syntax!
…<body> <h1 class="font:40 font:heavy italic m:12x text:center"> Hello World </h1></body>…
Open your browser to watch the changes.