close
logo
Rslib
Guide
Config
Blog
English
简体中文
Guide
Config
Blog
English
简体中文
logo
Rslib

Getting Started

Introduction
Quick start
Glossary
Packages

Solution

Node.js
React
Vue

Basic

CLI
Configure Rslib
Use TypeScript
Output format
Output structure
Upgrade Rslib

Advanced

Handle third-party dependencies
Output compatibility
Declaration files
Import static assets
Import SVGR
Import JSON files
Module Federation
Use Storybook

Migration

Modern.js Module
tsup

FAQ

Features FAQ
📝 Edit this page on GitHub
Previous PageReact
Next PageCLI

#Vue

In this document, you will learn how to build a Vue component library using Rslib. You can check out Vue related example projects in Examples.

NOTE
  1. Only Vue 3 is supported, Vue 2 is not supported.

  2. Vue's declaration files are generated by vue-tsc, so lib.dts / lib.redirect.dts / lib.banner.dts / lib.footer.dts are not effective in Vue projects.

#Create Vue project

You can use create-rslib to create a project with Rslib + Vue. Just execute the following command:

npm
yarn
pnpm
bun
npm create rslib@latest

Then select Vue when prompted to "Select template".

#Use Rslib in an existing project

For developing Vue components, you need to set the target to "web" in rslib.config.ts. This is crucial because Rslib sets target to "node" by default, which is different from Rsbuild's default target value.

To compile Vue (.vue single-file components), you need to register the rsbuild-plugin-unplugin-vue plugin based on unplugin-vue. This plugin will automatically add the necessary configurations for Vue build.

For example, register in rslib.config.ts:

rslib.config.ts
import { defineConfig } from '@rslib/core';
import { pluginUnpluginVue } from 'rsbuild-plugin-unplugin-vue'; 

export default defineConfig({
  lib: [
    // ...
  ],
  output: {
    target: 'web',
  },
  plugins: [pluginUnpluginVue(/** options here */)],
});
NOTE

Currently, the rsbuild-plugin-unplugin-vue plugin does not support packaging Vue SFC scoped CSS styles. You can choose styling solutions like Less or Sass.

For more configuration options, please refer to the rsbuild-plugin-unplugin-vue plugin documentation.