Installation
Installing Packages
To add Virgo UI to your project, use one of the following commands:
bashpnpm add @virgo-ui/vue
pnpm add @virgo-ui/vue
bashyarn add @virgo-ui/vue
yarn add @virgo-ui/vue
bashnpm install @virgo-ui/vue
npm install @virgo-ui/vue
Next, integrate Virgo into your
main.ts
as demonstrated below:jsimport { createApp } from 'vue' import App from './App.vue' import { virgo } from '@virgo-ui/vue' // Imports virgo styles, which include only transitions and a scroll-lock style import '@virgo-ui/vue/dist/style.css' // Applying `app.use(virgo)` to register the Virgo plugin createApp(App).use(virgo).mount('#app')
import { createApp } from 'vue' import App from './App.vue' import { virgo } from '@virgo-ui/vue' // Imports virgo styles, which include only transitions and a scroll-lock style import '@virgo-ui/vue/dist/style.css' // Applying `app.use(virgo)` to register the Virgo plugin createApp(App).use(virgo).mount('#app')
You're now ready to incorporate Virgo components within your Vue files:
<template>
<virgo-button>
<tooltip text="Hello!" />
Hover Over Me
</virgo-button>
</template>
<template>
<virgo-button>
<tooltip text="Hello!" />
Hover Over Me
</virgo-button>
</template>
NOTE
Explore the default designs on the Themes page. Also, ensure to review the theme documentation for comprehensive insights on themes. Note that this installation process doesn't include the specific configuration and designs presented in the documentation, meaning the components will remain unstyled.
Understanding the preference to not globally register components, here are alternative approaches:
Tree Shaking
Opt for an À la carte approach if global registration doesn't suit your project's needs.
Disable global registration of components by setting the
registerComponents
option tofalse
when initializing the Virgo plugin.diffimport { virgo } from '@virgo-ui/vue' createApp(App) - .use(virgo) + .use(virgo, { registerComponents: false }) .mount('#app')
import { virgo } from '@virgo-ui/vue' createApp(App) - .use(virgo) + .use(virgo, { registerComponents: false }) .mount('#app')
Subsequently, import the components you need individually from
@virgo-ui/vue
.vue<script setup> import { Tooltip } from '@virgo-ui/vue' </script> <template> <virgo-button> <tooltip text="Hello!" /> Hover Over Me </virgo-button> </template>
<script setup> import { Tooltip } from '@virgo-ui/vue' </script> <template> <virgo-button> <tooltip text="Hello!" /> Hover Over Me </virgo-button> </template>
Auto Importing Components with Tree Shaking
unplugin-vue-components facilitates the automatic, on-demand import of components, allowing you to skip explicit import statements while still benefiting from tree shaking.
First, ensure the
registerComponents
option is set tofalse
in yourmain.ts
if not already done.diffimport { virgo } from '@virgo-ui/vue' createApp(App) - .use(virgo) + .use(virgo, { registerComponents: false }) .mount('#app')
import { virgo } from '@virgo-ui/vue' createApp(App) - .use(virgo) + .use(virgo, { registerComponents: false }) .mount('#app')
Proceed to install
unplugin-vue-components
:bashpnpm add -D unplugin-vue-components
pnpm add -D unplugin-vue-components
bashyarn add -D unplugin-vue-components
yarn add -D unplugin-vue-components
bashnpm install --save-dev unplugin-vue-components
npm install --save-dev unplugin-vue-components
Configure
unplugin-vue-components
in yourvite.config.ts
:js// additional imports import Components from 'unplugin-vue-components/vite' import { VirgoResolver } from '@virgo-ui/vue' export default defineConfig({ plugins: [ // other plugins Components({ resolvers: [ VirgoResolver() ] }), ], // additional configurations })
// additional imports import Components from 'unplugin-vue-components/vite' import { VirgoResolver } from '@virgo-ui/vue' export default defineConfig({ plugins: [ // other plugins Components({ resolvers: [ VirgoResolver() ] }), ], // additional configurations })
Components can now be used directly in templates and will be automatically imported as needed.
vue<template> <virgo-button> <tooltip text="Hello!" /> Hover Over Me </virgo-button> </template>
<template> <virgo-button> <tooltip text="Hello!" /> Hover Over Me </virgo-button> </template>
Volar Support
For projects utilizing Volar, global component types can be specified by adding the following configuration to your jsconfig.json
or tsconfig.json
for TypeScript projects:
{
"compilerOptions": {
// other options...
"types": ["@virgo-ui/vue/volar"]
}
}
{
"compilerOptions": {
// other options...
"types": ["@virgo-ui/vue/volar"]
}
}
If you have a typescript project, you will have to configure the above in the tsconfig.json
file.