Skip to content

Commit

Permalink
docs: add unplugin-vue-components integration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ksem committed May 6, 2024
1 parent 6c66b72 commit 004e714
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 3 deletions.
13 changes: 13 additions & 0 deletions packages/docs/modules/page-config/blocks/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BaseBlock } from './../../runtime';
import { definePageConfigBlock } from '../../types'
import Component from './index.vue'

export default definePageConfigBlock({
setup (tabs: Record<string, BaseBlock[]>) {
return {
type: 'collapse' as const,
tabs
}
},
component: Component,
})
27 changes: 27 additions & 0 deletions packages/docs/modules/page-config/blocks/tabs/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<VaTabs v-model="value" class="mt-2">
<template #tabs>
<VaTab
v-for="tab in tabNames"
:key="tab"
>
{{ tab }}
</VaTab>
</template>
</VaTabs>
<PageConfigBlocks :blocks="tabs[tabNames[value]]" />
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { BaseBlock } from './../../runtime';
import PageConfigBlocks from '../../runtime/PageConfigBlocks.vue';
const value = ref(0)
const props = defineProps<{
tabs: Record<string, BaseBlock[]>
}>()
const tabNames = computed(() => Object.keys(props.tabs))
</script>
8 changes: 5 additions & 3 deletions packages/docs/modules/page-config/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import table from '../blocks/table'
import cards from '../blocks/cards'
import changeLog from '../blocks/change-log';
import tags from '../blocks/tags';
import tabs from '../blocks/tabs';
import { APIDescriptionOptions, type ManualApiOptions } from '../blocks/api/types'

// Need to define type in collapse without recursion
const blocksWithoutCollapse = {
const baseBlocks = {
alert,
example,
title,
Expand All @@ -44,12 +45,13 @@ const blocksWithoutCollapse = {
tags,
}

export type BaseBlock = ReturnType<(typeof blocksWithoutCollapse)[keyof typeof blocksWithoutCollapse]>
export type BaseBlock = ReturnType<(typeof baseBlocks)[keyof typeof baseBlocks]>

export const block = {
...blocksWithoutCollapse,
...baseBlocks,
collapse,
async,
tabs,
}

export type GlobalBlock = typeof block
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// vite.config.ts
import { defineConfig } from 'vite';
import Components from 'unplugin-vue-components/vite'

export default defineConfig({
plugins: [
Components({
resolvers: [
(componentName) => {
if (componentName.startsWith('Va'))
return { name: componentName, from: 'vuestic-ui' }
},
],
}),
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-vue-components/webpack').default({
resolvers: [
(componentName) => {
if (componentName.startsWith('Va'))
return { name: componentName, from: 'vuestic-ui' }
},
],
}),
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createApp } from "vue";
import { createVuesticEssential } from "vuestic-ui";
import "vuestic-ui/css";
import App from "./App.vue";

createApp(App)
.use(
createVuesticEssential({
config: {
/* ... */
},
})
)
.mount("#app");
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default definePageConfig({
blocks: [
block.title('Unplugin Vue Components'),
block.paragraph('[Unplugin Vue Components](https://github.com/unplugin/unplugin-vue-components) is a Vite/Webpack plugin that automatically imports Vue components from your dependencies.'),
block.paragraph('You can use to import components from Vuestic UI without registering them globally or importing them in every file.'),

block.tabs({
'vite': [
block.code('installation.vite')
],
'webpack': [
block.code('installation.webpack')
],
}),

block.paragraph('After installing the plugin, you can use components from Vuestic UI without importing them. But you need to prevent them from global registration. Use `createVuesticEssential` to register Vuestic without global components. Read more about tree-shaking [here](/getting-started/tree-shaking)'),

block.code('vuestic-setup'),

block.paragraph('When working with [Nuxt](/getting-started/nuxt) this feature is built-in.'),
]
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default definePageConfig({
block.title("Tree shaking"),
block.paragraph("If you plan to use only several components in your application and thus reduce the size of your bundle, you can use the Vuestic ESM build. Webpack (vue-cli) and Vite do that automatically."),

block.alert('It is recommended to use special tools like [Unplugin Vue Components](/extensions/unplugin-vue-components) for SPA Vite/Webpack or [Nuxt](/getting-started/nuxt) that tree-shake components automatically.', 'info'),

block.paragraph("First, you don't need to use `createVuestic` since it registers all the `vuestic` components globally. We have `createVuesticEssential` instead, which register only essential plugins. You can specify components to declare globally. Or you can import them later."),
block.code("tree-shaking"),
block.paragraph("You can also specify Vuestic subplugins as `plugins` option. "),
Expand Down
10 changes: 10 additions & 0 deletions packages/docs/page-config/navigationRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export const navigationRoutes: NavigationRoute[] = [
{
name: "tree-shaking",
displayName: "Tree Shaking",
meta: {
badge: navigationBadge.updated('1.9.9'),
}
},
{
name: "nuxt",
Expand Down Expand Up @@ -607,6 +610,13 @@ export const navigationRoutes: NavigationRoute[] = [
badge: navigationBadge.new('1.6.0'),
}
},
{
name: 'unplugin-vue-components',
displayName: 'Auto import plugin',
meta: {
badge: navigationBadge.new('1.9.9'),
}
}
],
},
];

0 comments on commit 004e714

Please sign in to comment.