可以参考我之前发布的vite快速搭建vue3项目文章来创建;也可以直接使用我开源Vue3.2+Ts+Vite3+Pinia+Element-Plus模板wocwin-admin
以下我以 wocwin-admin 项目为例
import Table from './src/index.vue'
import { withInstall } from '../withInstall'
const TTable = withInstall(Table)
export default TTable
...
import TTable from './table'
// 存储组件列表
const components = [
TTable,
....
]
// 插件注册:在 Vue 项目的入口文件中,通过 ( app.use(插件) ) 进行注册
const installComponents = (app: any) => {
components.forEach((comp: any) => {
app.component(comp.name as string, comp)
})
}
const install = (app: any, router?: any) => {
installComponents(app)
}
export default {
...components, // 按需引入
// 导出的对象必须具有 install,才能被 Vue.use() 方法安装
install
}
pnpm add vitepress -D
# Hello Vitepress
"scripts": {
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs"
},
---
layout: home
title: T-ui-plus
# titleTemplate: 选项卡描述
editLink: true
lastUpdated: true
hero:
name: T-ui-plus
text: vue3基础组件
tagline: Vue3 中基于Element-plus二次封装基础组件文档
image:
src: /img/wocwin.jpg
alt: t-ui-plus
actions:
- theme: brand
text: 安装指南
link: /components/
- theme: brand
text: 组件预览
link: /components/TSelect/base.md
features:
- icon:
title: 实际项目
details: 实际项目中碰到的疑点、难点,致力于更优的自我。。
- icon:
title: 基础组件
details: 基于Element-plus二次封装;使用组件 Demo 快速体验交互细节。。
- icon: ✈️
title: Vue驱动。
details: 享受 Vue3 + vite3 的开发体验,在 Markdown 中使用 Vue 组件,同时可以使用 Vue 来开发自定义主题。
---
<p style="display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;">
<a href="https://github.com/vuejs/vue" target="_blank">
<img src="https://img.shields.io/badge/vue-3.2.36-brightgreen.svg" alt="vue3">
</a>
<a href="https://gitee.com/wocwin/t-ui-plus/stargazers" target="_blank">
<img src="https://gitee.com/wocwin/t-ui-plus/badge/star.svg?theme=dark" alt="t-ui-plus">
</a>
<a href="https://github.com/wocwin/t-ui-plus/stargazers" target="_blank">
<img src="https://img.shields.io/github/stars/wocwin/t-ui-plus.svg" alt="t-ui-plus">
</a>
<a href="https://www.npmjs.com/package/@wocwin/t-ui-plus" target="_blank">
<img alt="npm" src="https://img.shields.io/npm/v/@wocwin/t-ui-plus.svg" />
</a>
</p>
修改后 页面如下:
页面效果如下
import { defineConfig } from 'vitepress'
export default defineConfig({
title: 'TuiPlus基础组件文档',
description: '基于Element-plus基础组件封装使用',
lang: 'cn-ZH',
base: '/t-ui-plus/',
lastUpdated: true,
themeConfig: {
logo: '/favicon.ico',
siteTitle: 'TuiPlus基础组件文档',
outline: 3,
socialLinks: [
{ icon: 'github', link: 'https://github.com/wocwin/t-ui-plus' }
],
nav:[
{
text: '安装指南',
link: '/components/'
},
{ text: '基础组件', link: '/components/TSelect/base.md' },
{
text: 'GitHub地址',
link: 'https://github.com/wocwin/t-ui-plus'
},
{
text: 'Gitee码云地址',
link: 'https://gitee.com/wocwin/t-ui-plus'
},
{
text: '博客',
items: [
{ text: 'CSDN', link: 'https://blog.csdn.net/cwin8951' },
{ text: '掘金', link: 'https://juejin.cn/user/888061128344087/posts' }
]
}
],
sidebar:{
'/components': [
{
text: '常用组件',
items: [
{ text: '下拉选择组件', link: '/components/TSelect/base.md' },
{ text: '下拉选择表格组件', link: '/components/TSelectTable/base.md' },
]
},
{
text: '复杂组件',
items: [
{ text: '条件查询组件', link: '/components/TQueryCondition/base.md' },
{ text: '表单组件', link: '/components/TForm/base.md' },
{ text: 'table组件', link: '/components/TTable/base.md' },
]
}
]
}
},
markdown: {
config(md) {
md.use(demoblock)
}
}
})
pnpm add vitepress-theme-demoblock -D
import { demoBlockPlugin } from 'vitepress-theme-demoblock'
export default defineConfig({
markdown: {
...
config(md) {
md.use(demoBlockPlugin, {
customClass: 'demoblock-custom'
})
}
}
})
/*docs\public\css\index.css*/
:root {
--vp-c-brand: #646cff;
--vp-c-brand-light: #747bff;
--vp-c-brand-lighter: #9499ff;
--vp-c-brand-lightest: #bcc0ff;
--vp-c-brand-dark: #535bf2;
--vp-c-brand-darker: #454ce1;
--demoblock-border:#e7e7e7;
--vp-code-block-bg: #f9fafb;
}
.demo-block .meta {
background-color: var(--vp-code-block-bg);
}
.demo-block .t_layout_page{
overflow: visible;
padding: 0;
}
.demo-block .t_layout_page .t_layout_page_item{
padding: 0;
margin: 0;
}
html.dark {
--vp-code-block-bg: var(--vp-c-bg-alt);
}
"scripts": {
"docs:dev": "pnpm run register:components && vitepress dev docs",
"docs:build": "pnpm run register:components && vitepress build docs",
"register:components": "vitepress-rc"
},
import DefaultTheme from 'vitepress/theme'
// 演示组件
import 'vitepress-theme-demoblock/dist/theme/styles/index.css'
import { useComponents } from './useComponents'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import locale from 'element-plus/lib/locale/lang/zh-cn'
// 图标并进行全局注册
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// 基于element-plus二次封装基础组件
import TuiPlus from '../../../packages'
import '../../public/css/index.css' // 静态css资源
export default {
...DefaultTheme,
enhanceApp({app}) {
// 注册ElementPlus
app.use(ElementPlus, {
locale // 语言设置
})
// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
// 全局注册基础组件
app.use(TuiPlus)
app.component('Demo', Demo)
app.component('DemoBlock', DemoBlock)
}
}
build: {
outDir: 'lib',
rollupOptions: {
// 请确保外部化那些你的库中不需要的依赖
external: ['vue'],
output: {
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
vue: 'Vue',
},
},
},
lib: {
entry: './packages/index.ts',
name: 't-ui-plus',
}
},
npm config get registry
npm config set registry https://registry.npmjs.org
如出现以下信息,则证明包发布成功:
npm i @wocwin/t-ui-plus
import TuiPlus from '@wocwin/t-ui-plus'
import '@wocwin/t-ui-plus/lib/style.css'
instance.use(TuiPlus)
例如我的要部署到https://wocwin.github.io/t-ui-plus;那需要定义base是:/t-ui-plus/
# 确保脚本抛出遇到的错误
set -e
# 生成静态文件
yarn run docs:build
# 进入生成的文件夹
cd docs/.vitepress/dist
git init
git add -A
git commit -m 'deploy'
# 如果发布到 https://<USERNAME>.github.io/<REPO>
git push -f https://github.com/wocwin/t-ui-plus.git master:gh-pages
cd -
"scripts": {
"deploy": "deploy.sh",
}
文档目录
gitHub组件地址
gitee码云组件地址
基于ElementUi&Antd再次封装基础组件文档
vue3+ts基于Element-plus再次封装基础组件文档
vite+vue3+ts项目搭建之集成qiankun