|
| 1 | +# vuepress2-plugin-demo-block |
| 2 | +## 介绍 |
| 3 | +基于Vuepress2的插件,它可以帮助你在编写组件库文档的时候增加示例代码和预览。 |
| 4 | + |
| 5 | +## 安装 |
| 6 | + |
| 7 | +### 安装 VuePress |
| 8 | + |
| 9 | +请参考 Vuepress2 官方文档,[点此查看](https://v2.vuepress.vuejs.org/zh/guide/getting-started.html) |
| 10 | + |
| 11 | +### 安装插件 |
| 12 | + |
| 13 | +使用 `yarn` 安装 `vuepress2-plugin-demo-block` 插件 |
| 14 | + |
| 15 | +```bash |
| 16 | +yarn add vuepress2-plugin-demo-block -D |
| 17 | +``` |
| 18 | + |
| 19 | +或者使用 `npm` 安装它: |
| 20 | + |
| 21 | +```bash |
| 22 | +npm i vuepress2-plugin-demo-block --save-dev |
| 23 | +``` |
| 24 | + |
| 25 | +如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。 |
| 26 | + |
| 27 | +### 配置插件 |
| 28 | + |
| 29 | +打开 .vuepress/config.js 文件,然后在合适的位置引用插件: |
| 30 | + |
| 31 | +- **配置扫描路径** `componentsDir` |
| 32 | + |
| 33 | +```js |
| 34 | +module.exports = { |
| 35 | + ... |
| 36 | + plugins: [[ |
| 37 | + 'vuepress2-plugin-demo-block', |
| 38 | + { |
| 39 | + componentsDir: path.resolve(__dirname, './../examples') |
| 40 | + } |
| 41 | + ]], |
| 42 | + ... |
| 43 | +} |
| 44 | +``` |
| 45 | +::: warning 注意 |
| 46 | +componentsDir 必传,为动态注册组件的基础路径,目录结构可参考 element-plus |
| 47 | +::: |
| 48 | + |
| 49 | +## 引入组件 |
| 50 | +可在`docs/.vuepress/clientAppEnhance.js`引入组件,需要注意的是,第三方库可能还需要依赖,例如`ant-design-vue`还需要`less`和`less-loader`,请自行安装 |
| 51 | + |
| 52 | +```js |
| 53 | +import { defineClientAppEnhance } from "@vuepress/client"; |
| 54 | + |
| 55 | +// import Antd from "ant-design-vue"; |
| 56 | +// import "ant-design-vue/dist/antd.css"; |
| 57 | + |
| 58 | +// import ElementPlus from "element-plus"; |
| 59 | +// import "element-plus/dist/index.css"; |
| 60 | + |
| 61 | +// import ArcoVue from '@arco-design/web-vue'; |
| 62 | +// import ArcoVueIcon from '@arco-design/web-vue/es/icon'; |
| 63 | +// import '@arco-design/web-vue/dist/arco.css'; |
| 64 | + |
| 65 | +export default defineClientAppEnhance(({ app, router, siteData }) => { |
| 66 | + // app.use(Antd) |
| 67 | + // app.use(ElementPlus) |
| 68 | + // app.use(ArcoVue); |
| 69 | + // app.use(ArcoVueIcon); |
| 70 | +}); |
| 71 | +``` |
0 commit comments