当前位置: 首页 > news >正文

已有项目添加vitepress

已有项目添加vitepress

  • 已有项目基本配置
  • 添加vitepress
    • 安装vitepress
    • 初始化vitepress项目
    • 运行vitepress项目
    • 在默认主题的基础上添加自定义主题
    • 在docs目录下的.md文件中使用vue组件
    • 打包vitepress项目
    • 预览vitepress项目

已有项目基本配置

1、使用vite-vue-ts搭建项目
2、UI组件库使用arco.design.vue
3、node 版本20.17.0
4、项目使用原子化样式 tailwindcss
5、pnpm 作为包管理工具

添加vitepress

已有的项目中添加vitepress

安装vitepress

pnpm add -D vitepress

初始化vitepress项目

pnpm vitepress init

官方文档给出的说明:

如果正在构建一个独立的 VitePress 站点,可以在当前目录 (./) 中搭建站点。但是,如果在现有项目中与其他源代码一起安装 VitePress,建议将站点搭建在嵌套目录 (例如 ./docs) 中,以便它与项目的其余部分分开。

在这里插入图片描述
生成的vitepress项目结构,以及3个script脚本,如下

在这里插入图片描述

运行vitepress项目

执行命令,打开地址就能看到vitepress生成的网页,如下:

pnpm docs:dev

在这里插入图片描述

在默认主题的基础上添加自定义主题

用于注册UI组件库( @arco-design/web-vu)和原子样式( tailwindcss)
docs/.vitepress目录下添加theme文件夹,结构如下:

docs
 -.vitepress
 	-theme
 		-index.ts
 		-style.css
 	-config.ts

theme/index.ts文件中添加如下代码:

import DefaultTheme from "vitepress/theme"
import ArcoVue from "@arco-design/web-vue"
import ArcoVueIcon from "@arco-design/web-vue/es/icon"
import "@arco-design/web-vue/dist/arco.css"
import "./style.css"

export default {
  ...DefaultTheme,
  NotFound: () => "404", // <- this is a Vue 3 functional component
  enhanceApp({ app }) { // 注册arco组件和图标
    app.use(ArcoVue).use(ArcoVueIcon)
  },
}

theme/style.css文件中添加如下代码:

/*导入原子样式*/
@tailwind base;
@tailwind components;
@tailwind utilities;

在config.ts文件添加vite配置,如下

export default defineConfig({
// ...其他配置
  vite: {
    ssr: {
      noExternal: ["@arco-design/web-vue"],
    },
  },
})

解决在打包时,报错
(node:6936) Warning: To load an ES module, set “type”: “module” in the package.json or use the .
(Use node --trace-warnings ... to show where the warning was created)
D:\projects\eon\node_modules.pnpm@arco-design+web-vue@2.55.3_vue@3.3.13_typescript@5.1.6_\node\icon\index.js:1
export { default } from “./arco-vue-icon.js”;
^^^^^^
SyntaxError: Unexpected token ‘export’

在docs目录下的.md文件中使用vue组件

vue组件如下(目录在, src/views/my-buttom.vue):

使用原子样式( tailwindcss),@arco-design/web-vue组件库中的Button 组件

// src/views/my-buttom.vue
<template>
    <Button type="primary" class="bg-[red]"> 按钮 </Button>
</template>
<script setup lang="ts">
import { Button } from "@arco-design/web-vue";
</script>

vitepress项目的index.md文件(目录在, docs/index.md):

md文件引用vue组件

#  docs/index.md
<MyBotton type="primary" class="bg-[red]"> 按钮 </Button>

<script setup>
import MyBotton from '../src/view/my-buttom.vue';
</script>

打包vitepress项目

打包成功就可以预览

pnpm docs:build

预览vitepress项目

pnpm docs:preview

相关文章:

  • 硬件基础(3):三极管(1):理论基础
  • 补题A-E Codeforces Round 953 (Div. 2)
  • 【Qt源码】窥视信号槽实现机制
  • jdk21下载、安装(Windows、Linux、macOS)
  • HTML转义和反转义工具类
  • @KafkaListener和KafkaTemplate自动装配原理分析
  • TLS与自签名证书的创建、作用、用到的工具等知识的介绍
  • 《MULTI-CLASS SEMANTIC SEGMENTATION OF FACES》论文分享(侵删)
  • pandas如何添加列
  • android进阶面试题目
  • 机器学习(部分算法、模型)
  • 【redis】数据类型之Bitfields
  • 网络安全入门|HTTP慢速攻击的终极防御:零信任与AI对抗
  • 信号——进程间通信(20250225)
  • 微软开源神器OmniParser-v2.0本地部署教程
  • vue3 封装通用 ECharts 组件
  • 绕过information_schema与order by注入以及seacsmv9注入
  • 使用open-webui调用大模型
  • Android ViewStub延迟初始化加载布局View,Kotlin
  • C++:开胃菜练习项目---定长内存池的实现以及测试
  • 用.net做的网站/营销推广软件
  • 天津网站建设培训班/seo资料
  • 常用博客建站程序/seo包括什么
  • 制作网站开发/营销型网站建设设计
  • 广州网站改版设计制作/seo免费入门教程
  • 果蔬网站规划建设方案/网站ip查询