@mc-markets/ui 1.1.5 → 1.1.7

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/RESOLVER_USAGE.md DELETED
@@ -1,286 +0,0 @@
1
- # @mc-markets/ui Resolver 使用指南
2
-
3
- ## 什么是 Resolver?
4
-
5
- Resolver 是 `unplugin-vue-components` 的一个功能,它可以自动识别和导入组件库的组件,无需手动导入。
6
-
7
- ## 安装
8
-
9
- 首先,确保你已经安装了必要的依赖:
10
-
11
- ```bash
12
- npm install @mc-markets/ui
13
- npm install -D unplugin-vue-components
14
- ```
15
-
16
- ## 使用方法
17
-
18
- ### Vite 配置
19
-
20
- #### ES 模块方式(推荐)
21
-
22
- 在你的 `vite.config.js` 或 `vite.config.ts` 中:
23
-
24
- ```js
25
- import { defineConfig } from 'vite'
26
- import vue from '@vitejs/plugin-vue'
27
- import Components from 'unplugin-vue-components/vite'
28
- import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
29
-
30
- export default defineConfig({
31
- plugins: [
32
- vue(),
33
- Components({
34
- resolvers: [
35
- McMarketsUiResolver({
36
- importStyle: true, // 自动导入样式
37
- styleType: 'css', // 样式类型: 'css' | 'scss'
38
- fallbackToElementPlus: false // 是否回退到 Element Plus
39
- })
40
- ]
41
- })
42
- ]
43
- })
44
- ```
45
-
46
- #### CommonJS 方式
47
-
48
- 如果你的配置文件使用 CommonJS 格式:
49
-
50
- ```js
51
- const { defineConfig } = require('vite')
52
- const vue = require('@vitejs/plugin-vue')
53
- const Components = require('unplugin-vue-components/vite')
54
- const { McMarketsUiResolver } = require('@mc-markets/ui/resolver')
55
-
56
- module.exports = defineConfig({
57
- plugins: [
58
- vue(),
59
- Components({
60
- resolvers: [
61
- McMarketsUiResolver({
62
- importStyle: true,
63
- styleType: 'css'
64
- })
65
- ]
66
- })
67
- ]
68
- })
69
- ```
70
-
71
- > **💡 提示**: Resolver 自动支持 ES 模块和 CommonJS 两种格式,无需额外配置。
72
-
73
- ### Webpack 配置
74
-
75
- 在你的 `webpack.config.js` 中:
76
-
77
- ```js
78
- const Components = require('unplugin-vue-components/webpack')
79
- const { McMarketsUiResolver } = require('@mc-markets/ui/resolver')
80
-
81
- module.exports = {
82
- plugins: [
83
- Components({
84
- resolvers: [McMarketsUiResolver()]
85
- })
86
- ]
87
- }
88
- ```
89
-
90
- ### Rollup 配置
91
-
92
- ```js
93
- import Components from 'unplugin-vue-components/rollup'
94
- import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
95
-
96
- export default {
97
- plugins: [
98
- Components({
99
- resolvers: [McMarketsUiResolver()]
100
- })
101
- ]
102
- }
103
- ```
104
-
105
- ## 配置选项
106
-
107
- ### importStyle
108
-
109
- - **类型**: `boolean`
110
- - **默认值**: `true`
111
- - **说明**: 是否自动导入样式文件
112
-
113
- ```js
114
- McMarketsUiResolver({
115
- importStyle: true // 会自动导入组件样式
116
- })
117
- ```
118
-
119
- ### styleType
120
-
121
- - **类型**: `'css' | 'scss'`
122
- - **默认值**: `'css'`
123
- - **说明**: 样式文件类型
124
-
125
- ```js
126
- // 使用 CSS 样式(打包后的)
127
- McMarketsUiResolver({
128
- styleType: 'css' // 导入 @mc-markets/ui/dist/style
129
- })
130
-
131
- // 使用 SCSS 样式(源文件)
132
- McMarketsUiResolver({
133
- styleType: 'scss' // 导入 @mc-markets/ui/styles/index
134
- })
135
- ```
136
-
137
- 如果使用 `scss`,需要确保项目中配置了 SCSS 处理器。
138
-
139
- ### fallbackToElementPlus
140
-
141
- - **类型**: `boolean`
142
- - **默认值**: `false`
143
- - **说明**: 对于未自定义的组件,是否回退到 Element Plus
144
-
145
- ```js
146
- McMarketsUiResolver({
147
- fallbackToElementPlus: true
148
- })
149
- ```
150
-
151
- 当设置为 `true` 时,如果使用了 `@mc-markets/ui` 未自定义的组件(如 `MCard`),会尝试从库中导入转换后的 Element Plus 组件。
152
-
153
- ## 使用示例
154
-
155
- 配置好 resolver 后,你可以直接在模板中使用组件,无需手动导入:
156
-
157
- ```vue
158
- <template>
159
- <div>
160
- <!-- 自动导入 MButton -->
161
- <m-button type="primary">主要按钮</m-button>
162
-
163
- <!-- 自动导入 MInput -->
164
- <m-input v-model="value" placeholder="请输入" />
165
-
166
- <!-- 自动导入 MDialog -->
167
- <m-dialog v-model="visible" title="对话框">
168
- <p>对话框内容</p>
169
- </m-dialog>
170
- </div>
171
- </template>
172
-
173
- <script setup>
174
- import { ref } from 'vue'
175
-
176
- const value = ref('')
177
- const visible = ref(false)
178
- </script>
179
- ```
180
-
181
- ## 与其他 Resolver 一起使用
182
-
183
- 你可以同时使用多个 resolver:
184
-
185
- ```js
186
- import { defineConfig } from 'vite'
187
- import Components from 'unplugin-vue-components/vite'
188
- import {
189
- McMarketsUiResolver
190
- } from '@mc-markets/ui/resolver'
191
- import {
192
- ElementPlusResolver,
193
- VantResolver
194
- } from 'unplugin-vue-components/resolvers'
195
-
196
- export default defineConfig({
197
- plugins: [
198
- Components({
199
- resolvers: [
200
- McMarketsUiResolver(),
201
- ElementPlusResolver(), // Element Plus 组件
202
- VantResolver() // Vant 组件
203
- ]
204
- })
205
- ]
206
- })
207
- ```
208
-
209
- ## 支持的组件
210
-
211
- 目前支持自动导入的自定义组件包括:
212
-
213
- - `MIcon` - 图标
214
- - `MButton` - 按钮
215
- - `MInput` - 输入框
216
- - `MForm` - 表单
217
- - `MFormItem` - 表单项
218
- - `MTooltip` - 文字提示
219
- - `MSelect` - 选择器
220
- - `MOption` - 选项
221
- - `MOptionGroup` - 选项组
222
- - `MPagination` - 分页
223
- - `MRadio` - 单选框
224
- - `MRadioGroup` - 单选框组
225
- - `MRadioButton` - 单选按钮
226
- - `MSwitch` - 开关
227
- - `MTag` - 标签
228
- - `MAlert` - 警告
229
- - `MDialog` - 对话框
230
- - `MNotification` - 通知
231
- - `MMessage` - 消息提示
232
- - `MNotifiMessage` - 通知消息
233
- - `MDatePicker` - 日期选择器
234
- - `MEmpty` - 空状态
235
- - `MTable` - 表格
236
- - `MTableColumn` - 表格列
237
- - `MBanner` - 横幅
238
- - `MTabs` - 标签页
239
- - `MTabPane` - 标签面板
240
- - `MTabCard` - 标签卡片
241
- - `MTabCardItem` - 标签卡片项
242
- - `MBreadcrumb` - 面包屑
243
-
244
- ## 注意事项
245
-
246
- 1. **组件前缀**: 所有组件必须使用 `M` 前缀(如 `MButton`、`MInput`)才能被 resolver 识别。
247
-
248
- 2. **样式导入**:
249
- - 如果使用 `styleType: 'css'`,会导入打包后的 CSS 文件
250
- - 如果使用 `styleType: 'scss'`,会导入源 SCSS 文件,需要项目支持 SCSS
251
-
252
- 3. **按需加载**: Resolver 会自动实现按需加载,只导入你使用的组件。
253
-
254
- 4. **类型支持**: Resolver 提供了完整的 TypeScript 类型定义。
255
-
256
- ## 常见问题
257
-
258
- ### Q: 组件没有被自动导入?
259
-
260
- A: 请确保:
261
- 1. 组件名称使用了 `M` 前缀(如 `<m-button>`)
262
- 2. Vite/Webpack 配置正确
263
- 3. 重启开发服务器
264
-
265
- ### Q: 样式没有生效?
266
-
267
- A: 请检查:
268
- 1. `importStyle` 选项是否设置为 `true`
269
- 2. 如果使用 `styleType: 'scss'`,确保项目配置了 SCSS 处理器
270
-
271
- ### Q: 可以和 Element Plus 一起使用吗?
272
-
273
- A: 可以!你可以同时使用 `McMarketsUiResolver` 和 `ElementPlusResolver`:
274
-
275
- ```js
276
- resolvers: [
277
- McMarketsUiResolver(),
278
- ElementPlusResolver()
279
- ]
280
- ```
281
-
282
- ## 更多资源
283
-
284
- - [unplugin-vue-components 文档](https://github.com/antfu/unplugin-vue-components)
285
- - [@mc-markets/ui 文档](https://daboluoxigua.github.io/mc-markets-ui/)
286
-
@@ -1,368 +0,0 @@
1
- # 样式导入指南
2
-
3
- 如果使用 resolver 后组件正常显示但样式缺失,可以尝试以下几种解决方案。
4
-
5
- ## 方案 1:手动导入全局样式(推荐)⭐
6
-
7
- 在你的项目入口文件(如 `main.js` 或 `main.ts`)中手动导入样式:
8
-
9
- ### CSS 方式
10
- ```js
11
- // main.js
12
- import { createApp } from 'vue'
13
- import App from './App.vue'
14
-
15
- // 手动导入 @mc-markets/ui 样式
16
- import '@mc-markets/ui/dist/style.css'
17
-
18
- createApp(App).mount('#app')
19
- ```
20
-
21
- ### SCSS 方式
22
- ```js
23
- // main.js
24
- import { createApp } from 'vue'
25
- import App from './App.vue'
26
-
27
- // 手动导入 @mc-markets/ui SCSS 样式
28
- import '@mc-markets/ui/styles/index.scss'
29
-
30
- createApp(App).mount('#app')
31
- ```
32
-
33
- > **💡 提示**: 这是最可靠的方式,确保样式在应用启动时就被加载。
34
-
35
- ## 方案 2:通过 Vite 配置导入
36
-
37
- 在 `vite.config.js` 中配置:
38
-
39
- ```js
40
- import { defineConfig } from 'vite'
41
-
42
- export default defineConfig({
43
- css: {
44
- preprocessorOptions: {
45
- scss: {
46
- // 如果使用 SCSS
47
- additionalData: `@use "@mc-markets/ui/styles/index.scss" as *;`
48
- }
49
- }
50
- }
51
- })
52
- ```
53
-
54
- 或者在 CSS 中导入:
55
-
56
- ```css
57
- /* src/style.css 或 src/main.css */
58
- @import '@mc-markets/ui/dist/style.css';
59
- ```
60
-
61
- 然后在 `main.js` 中导入这个 CSS 文件:
62
-
63
- ```js
64
- import './style.css'
65
- ```
66
-
67
- ## 方案 3:修改 Resolver 配置
68
-
69
- 确保 resolver 配置正确:
70
-
71
- ```js
72
- // vite.config.js
73
- import Components from 'unplugin-vue-components/vite'
74
- import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
75
-
76
- export default defineConfig({
77
- plugins: [
78
- Components({
79
- resolvers: [
80
- McMarketsUiResolver({
81
- importStyle: true, // 确保为 true
82
- styleType: 'css', // 'css' 或 'scss'
83
- })
84
- ]
85
- })
86
- ]
87
- })
88
- ```
89
-
90
- > **注意**: `sideEffects` 在某些版本的 unplugin-vue-components 中可能不完全支持。
91
-
92
- ## 方案 4:检查 unplugin-vue-components 版本
93
-
94
- 确保使用的是较新版本:
95
-
96
- ```bash
97
- npm list unplugin-vue-components
98
- ```
99
-
100
- 如果版本低于 0.24.0,建议升级:
101
-
102
- ```bash
103
- npm install -D unplugin-vue-components@latest
104
- ```
105
-
106
- ## 方案 5:单独导入样式到 HTML
107
-
108
- 在 `index.html` 中添加:
109
-
110
- ```html
111
- <!DOCTYPE html>
112
- <html lang="zh-CN">
113
- <head>
114
- <meta charset="UTF-8">
115
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
116
- <title>Your App</title>
117
-
118
- <!-- 方式 1: 如果已发布到 CDN -->
119
- <!-- <link rel="stylesheet" href="https://cdn.example.com/@mc-markets/ui/dist/style.css"> -->
120
-
121
- <!-- 方式 2: 通过 Vite 处理(推荐) -->
122
- <link rel="stylesheet" href="/node_modules/@mc-markets/ui/dist/style.css">
123
- </head>
124
- <body>
125
- <div id="app"></div>
126
- <script type="module" src="/src/main.js"></script>
127
- </body>
128
- </html>
129
- ```
130
-
131
- > **注意**: 这种方式需要确保路径正确,在生产环境可能需要调整。
132
-
133
- ## 完整示例
134
-
135
- ### 项目结构
136
-
137
- ```
138
- your-project/
139
- ├── src/
140
- │ ├── main.js # 入口文件
141
- │ ├── App.vue
142
- │ └── views/
143
- │ └── Home.vue
144
- ├── vite.config.js
145
- └── package.json
146
- ```
147
-
148
- ### main.js(推荐配置)
149
-
150
- ```js
151
- import { createApp } from 'vue'
152
- import App from './App.vue'
153
-
154
- // ✅ 方法1:直接导入 CSS(最简单)
155
- import '@mc-markets/ui/dist/style.css'
156
-
157
- // ✅ 方法2:导入 SCSS(需要配置 SCSS 预处理器)
158
- // import '@mc-markets/ui/styles/index.scss'
159
-
160
- const app = createApp(App)
161
- app.mount('#app')
162
- ```
163
-
164
- ### vite.config.js
165
-
166
- ```js
167
- import { defineConfig } from 'vite'
168
- import vue from '@vitejs/plugin-vue'
169
- import Components from 'unplugin-vue-components/vite'
170
- import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
171
-
172
- export default defineConfig({
173
- plugins: [
174
- vue(),
175
- Components({
176
- resolvers: [
177
- McMarketsUiResolver({
178
- importStyle: false, // ⚠️ 如果手动导入了样式,设为 false 避免重复
179
- // importStyle: true, // 或者设为 true 尝试自动导入
180
- })
181
- ],
182
- dts: 'src/components.d.ts'
183
- })
184
- ],
185
-
186
- // 如果使用 SCSS
187
- css: {
188
- preprocessorOptions: {
189
- scss: {
190
- additionalData: `@use "sass:math";`
191
- }
192
- }
193
- }
194
- })
195
- ```
196
-
197
- ### App.vue 或其他组件
198
-
199
- ```vue
200
- <template>
201
- <div class="app">
202
- <h1>测试 @mc-markets/ui</h1>
203
-
204
- <!-- 直接使用,无需导入 -->
205
- <m-button type="primary">主要按钮</m-button>
206
- <m-button type="success">成功按钮</m-button>
207
-
208
- <m-input v-model="value" placeholder="请输入" />
209
-
210
- <m-select v-model="selected">
211
- <m-option label="选项1" value="1" />
212
- <m-option label="选项2" value="2" />
213
- </m-select>
214
- </div>
215
- </template>
216
-
217
- <script setup>
218
- import { ref } from 'vue'
219
- // 注意:组件不需要手动导入
220
-
221
- const value = ref('')
222
- const selected = ref('')
223
- </script>
224
- ```
225
-
226
- ## 样式优先级问题
227
-
228
- 如果样式导入了但效果不对,可能是优先级问题。可以尝试:
229
-
230
- ### 1. 调整导入顺序
231
-
232
- ```js
233
- // main.js
234
- import 'element-plus/dist/index.css' // Element Plus 样式在前
235
- import '@mc-markets/ui/dist/style.css' // 自定义样式在后(优先级更高)
236
- ```
237
-
238
- ### 2. 使用 !important(不推荐)
239
-
240
- ```css
241
- /* 在你的全局样式中 */
242
- .m-button {
243
- /* 你的自定义样式 */
244
- background-color: #409eff !important;
245
- }
246
- ```
247
-
248
- ### 3. 增加选择器权重
249
-
250
- ```vue
251
- <style scoped>
252
- /* 增加选择器层级 */
253
- .app .m-button {
254
- /* 你的自定义样式 */
255
- }
256
- </style>
257
- ```
258
-
259
- ## 调试技巧
260
-
261
- ### 检查样式是否加载
262
-
263
- 打开浏览器开发者工具:
264
-
265
- 1. **Network 标签页**:查找 `style.css`,确认是否被加载
266
- 2. **Elements 标签页**:检查 `<head>` 中是否有样式标签
267
- 3. **Console 标签页**:查看是否有样式加载错误
268
-
269
- ### 查看生成的代码
270
-
271
- 检查浏览器中实际加载的代码:
272
-
273
- ```js
274
- // 在浏览器 Console 中运行
275
- document.querySelectorAll('style, link[rel="stylesheet"]').forEach(el => {
276
- console.log(el.outerHTML || el.textContent.substring(0, 100))
277
- })
278
- ```
279
-
280
- ## 常见问题
281
-
282
- ### Q1: 样式完全没加载
283
-
284
- **解决方法**:
285
- 1. 在 `main.js` 中手动导入 `import '@mc-markets/ui/dist/style.css'`
286
- 2. 重启开发服务器
287
- 3. 清除浏览器缓存
288
-
289
- ### Q2: 部分样式不生效
290
-
291
- **解决方法**:
292
- 1. 检查是否有 CSS 优先级冲突
293
- 2. 确保没有被其他样式覆盖
294
- 3. 使用浏览器开发者工具检查实际应用的样式
295
-
296
- ### Q3: SCSS 导入报错
297
-
298
- **解决方法**:
299
- ```bash
300
- # 确保安装了 sass
301
- npm install -D sass
302
-
303
- # 然后在 main.js 中导入
304
- import '@mc-markets/ui/styles/index.scss'
305
- ```
306
-
307
- ### Q4: 生产环境样式丢失
308
-
309
- **解决方法**:
310
- 1. 确保在 `main.js` 中导入样式
311
- 2. 检查 `vite.config.js` 的 build 配置
312
- 3. 确认 `package.json` 中 `files` 字段包含样式文件
313
-
314
- ## 推荐方案总结
315
-
316
- ### 🌟 最佳实践(推荐)
317
-
318
- ```js
319
- // main.js
320
- import { createApp } from 'vue'
321
- import App from './App.vue'
322
-
323
- // 1. 手动导入样式(最可靠)
324
- import '@mc-markets/ui/dist/style.css'
325
-
326
- // 2. 如果使用 Element Plus,确保顺序正确
327
- // import 'element-plus/dist/index.css'
328
- // import '@mc-markets/ui/dist/style.css'
329
-
330
- const app = createApp(App)
331
- app.mount('#app')
332
- ```
333
-
334
- ```js
335
- // vite.config.js
336
- import { defineConfig } from 'vite'
337
- import vue from '@vitejs/plugin-vue'
338
- import Components from 'unplugin-vue-components/vite'
339
- import { McMarketsUiResolver } from '@mc-markets/ui/resolver'
340
-
341
- export default defineConfig({
342
- plugins: [
343
- vue(),
344
- Components({
345
- resolvers: [
346
- McMarketsUiResolver({
347
- importStyle: false // 手动导入了,这里设为 false
348
- })
349
- ]
350
- })
351
- ]
352
- })
353
- ```
354
-
355
- 这样可以确保:
356
- - ✅ 样式一定会被加载
357
- - ✅ 开发和生产环境一致
358
- - ✅ 样式加载时机可控
359
- - ✅ 避免重复导入
360
-
361
- ## 需要帮助?
362
-
363
- 如果以上方法都不行,请检查:
364
- 1. `@mc-markets/ui` 版本(应该是 1.1.2 或更高)
365
- 2. 浏览器控制台是否有错误
366
- 3. Network 标签页中样式文件的加载情况
367
- 4. 尝试清除 `node_modules/.vite` 缓存后重启
368
-