Skip to content

Want to skip the docs? Check out pandamastery.com - the best way to learn Panda CSS

Frameworks

Using Vue

Easily use Panda with Vue with our dedicated integration.

Learn how to set up Panda CSS in a Vue project using the @pandacss/vite plugin.

Prefer PostCSS? Run panda init --postcss instead of the plugin step below and follow Using PostCSS. Everything else on this page stays the same.

Start a new project

Create Vite project

To get started, we will need to create a new Vue project using the official scaffolding tool (opens in a new tab).

If you don't enter any parameter, the CLI will guide you through the process of creating a new Vue app.

pnpm create vue@latest

You will be asked a few questions, answer them as follows:

Vue.js - The Progressive JavaScript Framework
 
 Project name: test-app
 Add TypeScript? Yes
 Add JSX Support? Yes
 Add Vue Router for Single Page Application development? No / Yes
 Add Pinia for state management? No / Yes
 Add Vitest for Unit Testing? No / Yes
 Add an End-to-End Testing Solution? No
 Add ESLint for code quality? No / Yes
 Add Prettier for code formatting? No / Yes

Enter the newly created directory and install the dependencies.

cd test-app
pnpm install

Install Panda

Install panda, the Vite plugin, and create your panda.config.ts file.

pnpm install -D @pandacss/dev @pandacss/vite
pnpm panda init

Add the Vite plugin

Add pandacss() to your Vite plugins. It generates the styled-system folder, injects the CSS, and keeps both up to date on save. No separate watcher needed.

vite.config.ts

import { defineConfig } from 'vite'
import pandacss from '@pandacss/vite'
import vue from '@vitejs/plugin-vue'
 
export default defineConfig({
  plugins: [pandacss(), vue()]
})

Update package.json scripts

Open your package.json file and update the scripts section as follows:

package.json

{
  "scripts": {
+    "prepare": "panda codegen",
    "dev": "vite",
    "build": "run-p type-check build-only",
    "preview": "vite preview",
    "build-only": "vite build"
  }
}

The plugin only runs with Vite. The "prepare" script covers type checking and your editor, which read styled-system before Vite starts, and lets the folder stay gitignored.

Configure the content

Make sure that all of the paths of your Vue components are included in the include section of the panda.config.ts file.

panda.config.ts

import { defineConfig } from '@pandacss/dev'
 
export default defineConfig({
  // Whether to use css reset
  preflight: true,
 
  // Where to look for your css declarations
  include: ['./src/**/*.{js,jsx,ts,tsx,vue}'],
 
  // Files to exclude
  exclude: [],
 
  // The output directory for your css system
  outdir: 'styled-system'
})

Configure CSS layers

Add this code to an src/index.css file and import it in the root component of your project.

src/index.css

@layer reset, base, tokens, recipes, utilities;

This file only sets the layer order. The plugin injects the generated CSS for you.

Start your build process

Run the following command to start your development server.

pnpm dev

Start using Panda

Now you can start using Panda CSS in your project. Here is the snippet of code that you can use in your src/App.vue file.

src/App.vue

<script setup lang="ts">
import { css } from "../styled-system/css";
</script>
 
<template>
  <div :class="css({ fontSize: '5xl', fontWeight: 'bold' })">Hello 🐼!</div>
</template>

Optional: drop the styling runtime

By default css() resolves class strings in the browser with a small runtime. Turn on source transforms and the plugin rewrites static calls to plain class strings at build time, so the runtime never ships:

vite.config.ts

plugins: [pandacss({ transform: true }), vue()]

Dynamic values keep their runtime form. See Source transforms.

Edit this page on GitHubView as markdown
Last updated on