Skip to content

Commit c017fed

Browse files
committed
build: ui包产物结构修改,完善ui包readme
1 parent 19358e1 commit c017fed

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

apps/docs/zh/guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import UI from '@mylib/ui';
4444
import '@mylib/ui/style.css';
4545
const app = createApp(App);
4646
app.use(UI);
47-
// tsconfig.json还需要添加以下配置以获得类型提示
47+
// tsconfig.json 还需要添加以下配置以获得类型提示
4848
// "types": ["@mylib/ui/global.d.ts"]
4949

5050
// 按需引入

packages/ui/README.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,63 @@ Vue 3 组件库,基于 Vue 3 + TypeScript 构建的现代化组件库。
1313
## 安装
1414

1515
```bash
16-
npm
1716
npm install @mylib/ui
1817

19-
yarn
2018
yarn add @mylib/ui
2119

22-
pnpm
2320
pnpm add @mylib/ui
2421
```
2522

2623
## 快速开始
2724

25+
### 全局引入
26+
2827
```ts
2928
// main.ts
3029
import { createApp } from 'vue';
30+
import App from './App.vue';
31+
3132
import VUI from '@mylib/ui';
3233
import '@mylib/ui/style.css';
33-
import App from './App.vue';
34+
3435
const app = createApp(App);
3536
app.use(VUI);
3637
app.mount('#app');
3738
```
3839

39-
## 按需引入
40+
### 按需引入
4041

4142
```ts
4243
// main.ts
4344
import { createApp } from 'vue';
45+
import App from './App.vue';
46+
4447
import { Button } from '@mylib/ui';
4548
import '@mylib/ui/style.css';
46-
import App from './App.vue';
49+
4750
const app = createApp(App);
4851
app.use(Button);
4952
app.mount('#app');
5053
```
5154

52-
## 组件列表
53-
54-
### 基础组件
55-
56-
- Button 按钮
57-
58-
### 反馈组件
59-
60-
- Dialog 对话框
61-
62-
## 目录结构
63-
64-
packages/ui/
65-
├── src/ # 组件源码
66-
│ ├── components/ # 组件
67-
│ ├── \_utils/ # 组件内部使用的相关工具函数
68-
│ └── index.ts # 入口文件
69-
├── dist/ # 构建输出目录
70-
├── types/ # 类型声明文件
71-
└── package.json # 包配置文件
55+
## 使用示例
56+
57+
```vue
58+
<template>
59+
<VButton @click="open = true">弹窗</VButton>
60+
<VButton type="primary">按钮</VButton>
61+
<VButton type="success">按钮</VButton>
62+
<VButton type="warning">按钮</VButton>
63+
<VButton type="danger">按钮</VButton>
64+
<VButton type="info">按钮</VButton>
65+
<VDialog v-model:open="open">
66+
<div> 弹窗测试2222 </div>
67+
</VDialog>
68+
</template>
69+
70+
<script setup lang="ts">
71+
import { VButton, VDialog } from '@mylib/ui';
72+
import { ref } from 'vue';
73+
const open = ref(false);
74+
</script>
75+
```

packages/ui/vite.config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ export default defineConfig({
5252
// 输出格式
5353
formats: ['es', 'cjs'],
5454
// 输出文件名
55-
fileName: (format) =>
56-
`${format === 'es' ? 'esm' : 'cjs'}/index.${format === 'es' ? 'mjs' : 'js'}`,
55+
fileName: (format) => {
56+
return `${format === 'es' ? 'esm' : 'cjs'}/[name].${format === 'es' ? 'mjs' : 'js'}`;
57+
},
5758
// CSS 输出文件名
58-
cssFileName: `style`,
59+
cssFileName: 'style',
5960
},
6061
rollupOptions: {
6162
// 外部依赖
@@ -64,6 +65,10 @@ export default defineConfig({
6465
output: {
6566
// 导出方式
6667
exports: 'named',
68+
// 保留原始模块结构,而不是将所有模块合并成一个大文件
69+
preserveModules: true,
70+
// 将 src 目录设置为模块的根目录,这样输出的文件就会直接从 src 的子目录开始,去掉 src 这一层。
71+
preserveModulesRoot: 'src',
6772
},
6873
},
6974
},

0 commit comments

Comments
 (0)