@mc-markets/ui 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/CLEAR_VITE_CACHE.md +0 -271
- package/FIX_EXPORT_ISSUE.md +0 -166
- package/QUICK_FIX_STYLE.md +0 -78
- package/RESOLVER_USAGE.md +0 -286
- package/STYLE_IMPORT_GUIDE.md +0 -368
- package/TEST_RESOLVER.md +0 -251
- package/vite.config.example.js +0 -68
package/TEST_RESOLVER.md
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
# 测试 Resolver 是否工作
|
|
2
|
-
|
|
3
|
-
## 快速测试步骤
|
|
4
|
-
|
|
5
|
-
### 1. 在你的项目中创建测试页面
|
|
6
|
-
|
|
7
|
-
在 `src/views` 或 `src/pages` 目录下创建 `TestMcUi.vue`:
|
|
8
|
-
|
|
9
|
-
```vue
|
|
10
|
-
<template>
|
|
11
|
-
<div class="test-mc-ui">
|
|
12
|
-
<h1>测试 @mc-markets/ui Resolver</h1>
|
|
13
|
-
|
|
14
|
-
<!-- 使用 M 开头的组件 -->
|
|
15
|
-
<div class="test-section">
|
|
16
|
-
<h2>按钮测试</h2>
|
|
17
|
-
<m-button type="primary">主要按钮</m-button>
|
|
18
|
-
<m-button type="success">成功按钮</m-button>
|
|
19
|
-
</div>
|
|
20
|
-
|
|
21
|
-
<div class="test-section">
|
|
22
|
-
<h2>输入框测试</h2>
|
|
23
|
-
<m-input v-model="inputValue" placeholder="测试输入" />
|
|
24
|
-
<p>值: {{ inputValue }}</p>
|
|
25
|
-
</div>
|
|
26
|
-
|
|
27
|
-
<div class="test-section">
|
|
28
|
-
<h2>选择器测试</h2>
|
|
29
|
-
<m-select v-model="selectValue" placeholder="请选择">
|
|
30
|
-
<m-option label="选项1" value="1" />
|
|
31
|
-
<m-option label="选项2" value="2" />
|
|
32
|
-
</m-select>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<div class="test-section">
|
|
36
|
-
<h2>表单测试</h2>
|
|
37
|
-
<m-form>
|
|
38
|
-
<m-form-item label="用户名">
|
|
39
|
-
<m-input v-model="username" />
|
|
40
|
-
</m-form-item>
|
|
41
|
-
</m-form>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
</template>
|
|
45
|
-
|
|
46
|
-
<script setup>
|
|
47
|
-
import { ref } from 'vue'
|
|
48
|
-
|
|
49
|
-
// 注意:不需要手动导入组件,resolver 会自动处理
|
|
50
|
-
// import { MButton, MInput } from '@mc-markets/ui'
|
|
51
|
-
|
|
52
|
-
const inputValue = ref('')
|
|
53
|
-
const selectValue = ref('')
|
|
54
|
-
const username = ref('')
|
|
55
|
-
</script>
|
|
56
|
-
|
|
57
|
-
<style scoped>
|
|
58
|
-
.test-mc-ui {
|
|
59
|
-
padding: 20px;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.test-section {
|
|
63
|
-
margin-bottom: 30px;
|
|
64
|
-
padding: 20px;
|
|
65
|
-
border: 1px solid #ddd;
|
|
66
|
-
border-radius: 4px;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.test-section h2 {
|
|
70
|
-
margin-top: 0;
|
|
71
|
-
}
|
|
72
|
-
</style>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### 2. 访问测试页面
|
|
76
|
-
|
|
77
|
-
访问这个页面后,重新检查 `components.d.ts` 文件,应该会看到类似这样的内容:
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
declare module 'vue' {
|
|
81
|
-
export interface GlobalComponents {
|
|
82
|
-
// ... 其他组件
|
|
83
|
-
MButton: typeof import('@mc-markets/ui')['MButton']
|
|
84
|
-
MInput: typeof import('@mc-markets/ui')['MInput']
|
|
85
|
-
MSelect: typeof import('@mc-markets/ui')['MSelect']
|
|
86
|
-
MOption: typeof import('@mc-markets/ui')['MOption']
|
|
87
|
-
MForm: typeof import('@mc-markets/ui')['MForm']
|
|
88
|
-
MFormItem: typeof import('@mc-markets/ui')['MFormItem']
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### 3. 验证自动导入
|
|
94
|
-
|
|
95
|
-
如果看到上面的类型定义,说明 resolver 工作正常!你应该能够:
|
|
96
|
-
|
|
97
|
-
✅ 在模板中直接使用 `<m-button>`、`<m-input>` 等组件
|
|
98
|
-
✅ 无需手动 import
|
|
99
|
-
✅ 组件样式自动加载
|
|
100
|
-
✅ TypeScript 类型提示正常
|
|
101
|
-
|
|
102
|
-
### 4. 检查配置
|
|
103
|
-
|
|
104
|
-
如果没有生成类型定义,请检查你的 `vite.config.js`:
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
import Components from 'unplugin-vue-components/vite'
|
|
108
|
-
import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
|
|
109
|
-
|
|
110
|
-
export default {
|
|
111
|
-
plugins: [
|
|
112
|
-
Components({
|
|
113
|
-
resolvers: [
|
|
114
|
-
McMarketsUiResolver({
|
|
115
|
-
importStyle: true,
|
|
116
|
-
styleType: 'css'
|
|
117
|
-
})
|
|
118
|
-
],
|
|
119
|
-
// 确保 dts 路径正确
|
|
120
|
-
dts: 'src/components.d.ts'
|
|
121
|
-
})
|
|
122
|
-
]
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### 5. 常见问题排查
|
|
127
|
-
|
|
128
|
-
#### 问题:组件没有被识别
|
|
129
|
-
|
|
130
|
-
**解决方法**:
|
|
131
|
-
1. 确保组件名称使用 `M` 开头(大写)
|
|
132
|
-
2. 重启开发服务器 `npm run dev`
|
|
133
|
-
3. 删除 `node_modules/.vite` 缓存
|
|
134
|
-
|
|
135
|
-
#### 问题:类型定义没有生成
|
|
136
|
-
|
|
137
|
-
**解决方法**:
|
|
138
|
-
1. 检查 `dts` 配置路径是否正确
|
|
139
|
-
2. 确保 `unplugin-vue-components` 版本 >= 0.24.0
|
|
140
|
-
3. 查看控制台是否有错误信息
|
|
141
|
-
|
|
142
|
-
#### 问题:样式没有加载
|
|
143
|
-
|
|
144
|
-
**解决方法**:
|
|
145
|
-
```js
|
|
146
|
-
// 手动导入样式
|
|
147
|
-
import '@mc-markets/ui/dist/style'
|
|
148
|
-
|
|
149
|
-
// 或者在 vite.config.js 中配置
|
|
150
|
-
McMarketsUiResolver({
|
|
151
|
-
importStyle: true,
|
|
152
|
-
styleType: 'css' // 或 'scss'
|
|
153
|
-
})
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### 6. 查看构建结果
|
|
157
|
-
|
|
158
|
-
构建项目查看是否按需加载:
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
npm run build
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
检查 `dist` 目录,只有使用的组件会被打包进去。
|
|
165
|
-
|
|
166
|
-
## 直接测试 Resolver
|
|
167
|
-
|
|
168
|
-
你也可以直接测试 resolver 函数:
|
|
169
|
-
|
|
170
|
-
```js
|
|
171
|
-
// test-resolver.js
|
|
172
|
-
import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
|
|
173
|
-
|
|
174
|
-
const resolver = McMarketsUiResolver({
|
|
175
|
-
importStyle: true,
|
|
176
|
-
styleType: 'css'
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
// 测试不同组件
|
|
180
|
-
console.log('MButton:', resolver.resolve('MButton'))
|
|
181
|
-
console.log('MInput:', resolver.resolve('MInput'))
|
|
182
|
-
console.log('MTable:', resolver.resolve('MTable'))
|
|
183
|
-
console.log('ElButton:', resolver.resolve('ElButton')) // 应该返回 undefined
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
运行:
|
|
187
|
-
```bash
|
|
188
|
-
node test-resolver.js
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
预期输出:
|
|
192
|
-
```js
|
|
193
|
-
MButton: {
|
|
194
|
-
name: 'MButton',
|
|
195
|
-
from: '@mc-markets/ui',
|
|
196
|
-
sideEffects: '@mc-markets/ui/dist/style'
|
|
197
|
-
}
|
|
198
|
-
MInput: {
|
|
199
|
-
name: 'MInput',
|
|
200
|
-
from: '@mc-markets/ui',
|
|
201
|
-
sideEffects: '@mc-markets/ui/dist/style'
|
|
202
|
-
}
|
|
203
|
-
// ...
|
|
204
|
-
ElButton: undefined
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
## 支持的所有组件
|
|
208
|
-
|
|
209
|
-
确保以下组件名称都是 **M 开头**(而不是 m 开头):
|
|
210
|
-
|
|
211
|
-
- `MIcon`
|
|
212
|
-
- `MButton`
|
|
213
|
-
- `MInput`
|
|
214
|
-
- `MForm`
|
|
215
|
-
- `MFormItem`
|
|
216
|
-
- `MTooltip`
|
|
217
|
-
- `MSelect`
|
|
218
|
-
- `MOption`
|
|
219
|
-
- `MOptionGroup`
|
|
220
|
-
- `MPagination`
|
|
221
|
-
- `MRadio`
|
|
222
|
-
- `MRadioGroup`
|
|
223
|
-
- `MRadioButton`
|
|
224
|
-
- `MSwitch`
|
|
225
|
-
- `MTag`
|
|
226
|
-
- `MAlert`
|
|
227
|
-
- `MDialog`
|
|
228
|
-
- `MNotification`
|
|
229
|
-
- `MMessage`
|
|
230
|
-
- `MNotifiMessage`
|
|
231
|
-
- `MDatePicker`
|
|
232
|
-
- `MEmpty`
|
|
233
|
-
- `MTable`
|
|
234
|
-
- `MTableColumn`
|
|
235
|
-
- `MBanner`
|
|
236
|
-
- `MTabs`
|
|
237
|
-
- `MTabPane`
|
|
238
|
-
- `MTabCard`
|
|
239
|
-
- `MTabCardItem`
|
|
240
|
-
- `MBreadcrumb`
|
|
241
|
-
|
|
242
|
-
## 注意事项
|
|
243
|
-
|
|
244
|
-
⚠️ **重要**:组件名称必须使用 PascalCase(大驼峰)格式:
|
|
245
|
-
- ✅ 正确:`<MButton>` 或 `<m-button>` (在模板中会自动转换)
|
|
246
|
-
- ✅ 正确:`<MFormItem>` 或 `<m-form-item>`
|
|
247
|
-
- ❌ 错误:`<mButton>`
|
|
248
|
-
- ❌ 错误:`<mbutton>`
|
|
249
|
-
|
|
250
|
-
在 Vue 模板中,`<m-button>` 会被自动转换为 `MButton` 组件名。
|
|
251
|
-
|
package/vite.config.example.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @mc-markets/ui Vite 配置示例
|
|
3
|
-
*
|
|
4
|
-
* 这个文件展示了如何在你的项目中使用 @mc-markets/ui 和自动导入功能
|
|
5
|
-
* 复制此文件并根据你的需求进行修改
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { defineConfig } from 'vite'
|
|
9
|
-
import vue from '@vitejs/plugin-vue'
|
|
10
|
-
import Components from 'unplugin-vue-components/vite'
|
|
11
|
-
import AutoImport from 'unplugin-auto-import/vite'
|
|
12
|
-
import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
|
|
13
|
-
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
14
|
-
|
|
15
|
-
// https://vitejs.dev/config/
|
|
16
|
-
export default defineConfig({
|
|
17
|
-
plugins: [
|
|
18
|
-
vue(),
|
|
19
|
-
|
|
20
|
-
// 自动导入 API
|
|
21
|
-
AutoImport({
|
|
22
|
-
imports: [
|
|
23
|
-
'vue',
|
|
24
|
-
'vue-router',
|
|
25
|
-
'pinia'
|
|
26
|
-
],
|
|
27
|
-
resolvers: [
|
|
28
|
-
// Element Plus 自动导入
|
|
29
|
-
ElementPlusResolver()
|
|
30
|
-
],
|
|
31
|
-
dts: 'src/auto-imports.d.ts',
|
|
32
|
-
}),
|
|
33
|
-
|
|
34
|
-
// 自动导入组件
|
|
35
|
-
Components({
|
|
36
|
-
resolvers: [
|
|
37
|
-
// @mc-markets/ui 组件自动导入
|
|
38
|
-
McMarketsUiResolver({
|
|
39
|
-
importStyle: true, // 自动导入样式
|
|
40
|
-
styleType: 'css', // 使用 CSS 样式(或 'scss')
|
|
41
|
-
fallbackToElementPlus: false // 不回退到 Element Plus
|
|
42
|
-
}),
|
|
43
|
-
|
|
44
|
-
// Element Plus 组件自动导入(可选)
|
|
45
|
-
ElementPlusResolver({
|
|
46
|
-
importStyle: 'sass',
|
|
47
|
-
})
|
|
48
|
-
],
|
|
49
|
-
dts: 'src/components.d.ts',
|
|
50
|
-
})
|
|
51
|
-
],
|
|
52
|
-
|
|
53
|
-
resolve: {
|
|
54
|
-
alias: {
|
|
55
|
-
'@': '/src',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
css: {
|
|
60
|
-
preprocessorOptions: {
|
|
61
|
-
scss: {
|
|
62
|
-
// 如果使用 SCSS,可以在这里配置
|
|
63
|
-
additionalData: `@use "@mc-markets/ui/styles/variables/index.scss" as *;`
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|