Set up Master CSS in Nuxt.js
Guide to setting up Master CSS in your Nuxt.js 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 ~16KB transfer cost
Fully automatic
Capture any program-generated class names
CSS lifecycle
CSS is 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 nuxtjs.rr.beta.css.master.co.
You can skip all installation steps.
npx degit master-co/css/examples/nuxt.js-with-runtime-rendering my-projectcd my-projectnpm install @master/css.vue@betanpm installnpm run dev
Installation
Create a project
If you don't have a Nuxt.js project, create one first. It's recommended to refer to Get started with Nuxt.js.
npx nuxi@latest init projectcd project
Install Master CSS
Install Master CSS Vue into your project via package managers.
npm install @master/css.vue@beta
Initialize configuration file
Run npx mcss init
to create a configuration file master.css.ts.
npx mcss init
Set up CSS runtime engine
- Import your custom configuration
master.css.ts
- Initialize the runtime engine using
CSSProvider
<script setup lang="ts">import { CSSProvider } from '@master/css.vue'import config from './master.css'</script> <template> <CSSProvider :config="config"> … </CSSProvider></template>
Avoid flash of unstyled content
Configure nuxt.config.js
and add display: 'none'
in <html>
to avoid FOUC caused by the runtime engine not yet injecting CSS rules.
export default defineNuxtConfig({ app: { head: { script: [ { innerHTML: 'document.documentElement.style.display = "none"' } ] } }})
Launch server
Run npm run dev
to start your Nuxt.js development server
npm run dev
Start using Master CSS
Now style your first element using Master CSS syntax!
<template> <h1 class="font:40 font:heavy italic m:50 text:center">Hello World</h1></template>
Open your browser to watch the changes.