@phelan/design 0.0.1
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.specstory/history/2025-11-28_08-55Z-/345/210/235/345/247/213/345/214/226/345/211/215/347/253/257/347/273/204/344/273/266/345/272/223/351/241/271/347/233/256.md +4742 -0
- package/.specstory/history/2025-12-01_01-58Z-/345/210/235/345/247/213/345/214/226/345/211/215/347/253/257/347/273/204/344/273/266/345/272/223/351/241/271/347/233/256.md +14912 -0
- package/.specstory/history/2025-12-22_01-38Z-scss-/345/217/230/351/207/217/345/274/225/345/205/245/351/227/256/351/242/230.md +67163 -0
- package/.specstory/history/2026-01-08_03-51Z-pnpm-lines-88-95.md +304 -0
- package/README.en.md +36 -0
- package/README.md +37 -0
- package/SETUP_GUIDE.md +2530 -0
- package/docs/.vitepress/config.ts +298 -0
- package/docs/.vitepress/theme/index.ts +30 -0
- package/docs/.vitepress/theme/style.css +150 -0
- package/docs/CHANGELOG.md +7 -0
- package/docs/DEPLOY.md +183 -0
- package/docs/api-examples.md +49 -0
- package/docs/components/Changelog.vue +176 -0
- package/docs/components/ComponentOverview.vue +613 -0
- package/docs/components/ComponentSearch.vue +39 -0
- package/docs/components/basic/action-menu.md +63 -0
- package/docs/components/basic/arrow-steps.md +55 -0
- package/docs/components/basic/badge.md +22 -0
- package/docs/components/basic/batch-copy.md +44 -0
- package/docs/components/basic/batch-editor.md +52 -0
- package/docs/components/basic/border.md +22 -0
- package/docs/components/basic/breadcrumb.md +38 -0
- package/docs/components/basic/button.md +109 -0
- package/docs/components/basic/calendar.md +111 -0
- package/docs/components/basic/card.md +59 -0
- package/docs/components/basic/carousel.md +22 -0
- package/docs/components/basic/cascader.md +162 -0
- package/docs/components/basic/checkbox.md +171 -0
- package/docs/components/basic/collapse.md +22 -0
- package/docs/components/basic/column-table.md +123 -0
- package/docs/components/basic/date-picker.md +92 -0
- package/docs/components/basic/date-time-picker.md +110 -0
- package/docs/components/basic/demo.md +29 -0
- package/docs/components/basic/description.md +56 -0
- package/docs/components/basic/dialog.md +142 -0
- package/docs/components/basic/drawer.md +159 -0
- package/docs/components/basic/editor.md +76 -0
- package/docs/components/basic/empty.md +59 -0
- package/docs/components/basic/file-task-dialog.md +41 -0
- package/docs/components/basic/form.md +112 -0
- package/docs/components/basic/icon.md +53 -0
- package/docs/components/basic/image.md +110 -0
- package/docs/components/basic/import-dialog.md +54 -0
- package/docs/components/basic/independent-nav.md +45 -0
- package/docs/components/basic/input-number.md +61 -0
- package/docs/components/basic/input.md +98 -0
- package/docs/components/basic/layout.md +141 -0
- package/docs/components/basic/link.md +65 -0
- package/docs/components/basic/mention.md +22 -0
- package/docs/components/basic/message.md +167 -0
- package/docs/components/basic/nav.md +29 -0
- package/docs/components/basic/pagination.md +93 -0
- package/docs/components/basic/popover.md +116 -0
- package/docs/components/basic/progress.md +22 -0
- package/docs/components/basic/radio.md +152 -0
- package/docs/components/basic/result.md +22 -0
- package/docs/components/basic/scrollbar.md +105 -0
- package/docs/components/basic/search-panel.md +53 -0
- package/docs/components/basic/select.md +256 -0
- package/docs/components/basic/slider.md +22 -0
- package/docs/components/basic/space.md +140 -0
- package/docs/components/basic/steps.md +60 -0
- package/docs/components/basic/switch.md +115 -0
- package/docs/components/basic/table-grid.md +116 -0
- package/docs/components/basic/table-head-editor.md +135 -0
- package/docs/components/basic/table.md +433 -0
- package/docs/components/basic/tabs.md +62 -0
- package/docs/components/basic/tag.md +75 -0
- package/docs/components/basic/text.md +22 -0
- package/docs/components/basic/time-picker.md +77 -0
- package/docs/components/basic/time-select.md +65 -0
- package/docs/components/basic/tooltip.md +112 -0
- package/docs/components/basic/tour.md +22 -0
- package/docs/components/basic/tree-select.md +132 -0
- package/docs/components/basic/tree.md +163 -0
- package/docs/components/button.md +113 -0
- package/docs/components/calendar.md +111 -0
- package/docs/components/design/color.md +137 -0
- package/docs/components/index.md +3 -0
- package/docs/components/link.md +65 -0
- package/docs/components/search-panel.md +53 -0
- package/docs/components/table-grid.md +120 -0
- package/docs/components/table.md +433 -0
- package/docs/examples/action-menu/basic.vue +70 -0
- package/docs/examples/action-menu/default.vue +88 -0
- package/docs/examples/action-menu/index.vue +76 -0
- package/docs/examples/arrow-steps/index.vue +15 -0
- package/docs/examples/badge/index.vue +3 -0
- package/docs/examples/batch-copy/index.vue +30 -0
- package/docs/examples/batch-copy/validator.vue +73 -0
- package/docs/examples/batch-editor/basic.vue +120 -0
- package/docs/examples/batch-editor/customization.vue +167 -0
- package/docs/examples/border/index.vue +3 -0
- package/docs/examples/breadcrumb/index.vue +33 -0
- package/docs/examples/button/demo1.vue +119 -0
- package/docs/examples/button/demo2.vue +18 -0
- package/docs/examples/button/demo3.vue +32 -0
- package/docs/examples/button/demo4.vue +41 -0
- package/docs/examples/button/demo5.vue +46 -0
- package/docs/examples/button/demo6.vue +35 -0
- package/docs/examples/calendar/calendar01.vue +46 -0
- package/docs/examples/calendar/calendar02.vue +16 -0
- package/docs/examples/calendar/calendar03.vue +6 -0
- package/docs/examples/calendar/calendar04.vue +54 -0
- package/docs/examples/calendar/calendar05.vue +36 -0
- package/docs/examples/calendar/calendar06.vue +53 -0
- package/docs/examples/card/basic-card.vue +7 -0
- package/docs/examples/card/card-title.vue +6 -0
- package/docs/examples/card/collapsible-card.vue +26 -0
- package/docs/examples/card/title-card.vue +32 -0
- package/docs/examples/carousel/index.vue +3 -0
- package/docs/examples/cascader/clearable.vue +52 -0
- package/docs/examples/cascader/collapse-tags.vue +84 -0
- package/docs/examples/cascader/disabled-select.vue +52 -0
- package/docs/examples/cascader/disabled.vue +54 -0
- package/docs/examples/cascader/filterable.vue +82 -0
- package/docs/examples/cascader/index.vue +173 -0
- package/docs/examples/cascader/multiple.vue +74 -0
- package/docs/examples/cascader/show-all-levels.vue +63 -0
- package/docs/examples/cascader/sizes.vue +71 -0
- package/docs/examples/checkbox/basic.vue +47 -0
- package/docs/examples/checkbox/button-style.vue +73 -0
- package/docs/examples/checkbox/disabled.vue +20 -0
- package/docs/examples/checkbox/grouping.vue +32 -0
- package/docs/examples/checkbox/intermediate.vue +43 -0
- package/docs/examples/checkbox/limitation.vue +23 -0
- package/docs/examples/checkbox/with-border.vue +74 -0
- package/docs/examples/collapse/index.vue +3 -0
- package/docs/examples/column-table/basic.vue +47 -0
- package/docs/examples/column-table/column-title.vue +48 -0
- package/docs/examples/column-table/custom.vue +125 -0
- package/docs/examples/column-table/index.vue +209 -0
- package/docs/examples/column-table/nested.vue +123 -0
- package/docs/examples/column-table/no-header.vue +50 -0
- package/docs/examples/date-picker/default.vue +106 -0
- package/docs/examples/date-picker/index.vue +98 -0
- package/docs/examples/date-picker/otherUnits.vue +118 -0
- package/docs/examples/date-picker/periodTime.vue +108 -0
- package/docs/examples/date-time-picker/default.vue +83 -0
- package/docs/examples/date-time-picker/format.vue +90 -0
- package/docs/examples/date-time-picker/index.vue +110 -0
- package/docs/examples/date-time-picker/range.vue +111 -0
- package/docs/examples/date-time-picker/time-format.vue +78 -0
- package/docs/examples/demo/demo1.vue +3 -0
- package/docs/examples/demo/demo2.vue +3 -0
- package/docs/examples/description/custom-description.vue +30 -0
- package/docs/examples/description/index.vue +13 -0
- package/docs/examples/description/labelJustify.vue +58 -0
- package/docs/examples/description/merge-description.vue +15 -0
- package/docs/examples/design/color-palette.vue +225 -0
- package/docs/examples/dialog/align-center.vue +34 -0
- package/docs/examples/dialog/basic.vue +31 -0
- package/docs/examples/dialog/centered-content.vue +34 -0
- package/docs/examples/dialog/customization-content.vue +129 -0
- package/docs/examples/dialog/customization-header.vue +60 -0
- package/docs/examples/dialog/msg-dialog.vue +63 -0
- package/docs/examples/dialog/nested-dialog.vue +43 -0
- package/docs/examples/dialog/title-icon.vue +32 -0
- package/docs/examples/drawer/custom-content.vue +182 -0
- package/docs/examples/drawer/custom-header.vue +30 -0
- package/docs/examples/drawer/index.vue +101 -0
- package/docs/examples/drawer/modal.vue +40 -0
- package/docs/examples/drawer/nested.vue +44 -0
- package/docs/examples/drawer/no-title.vue +22 -0
- package/docs/examples/drawer/resizable.vue +28 -0
- package/docs/examples/editor/basic.vue +53 -0
- package/docs/examples/editor/customization-desc.vue +56 -0
- package/docs/examples/editor/more-demo.vue +54 -0
- package/docs/examples/editor/more-form.vue +56 -0
- package/docs/examples/editor/number-desc.vue +55 -0
- package/docs/examples/empty/basic.vue +4 -0
- package/docs/examples/empty/bottom-content.vue +5 -0
- package/docs/examples/empty/custom-image.vue +6 -0
- package/docs/examples/empty/image-size.vue +6 -0
- package/docs/examples/file-task-dialog/index.vue +52 -0
- package/docs/examples/form/accessibility.vue +48 -0
- package/docs/examples/form/alignment.vue +68 -0
- package/docs/examples/form/basic-form.vue +120 -0
- package/docs/examples/form/custom-validation.vue +121 -0
- package/docs/examples/form/form-items.vue +111 -0
- package/docs/examples/form/inline-form.vue +70 -0
- package/docs/examples/form/number-validate.vue +60 -0
- package/docs/examples/form/size-control.vue +140 -0
- package/docs/examples/form/validation.vue +265 -0
- package/docs/examples/icon/icon.vue +52 -0
- package/docs/examples/icon/index.vue +7 -0
- package/docs/examples/image/error.vue +69 -0
- package/docs/examples/image/index.vue +47 -0
- package/docs/examples/image/lazy.vue +39 -0
- package/docs/examples/image/placeholder.vue +69 -0
- package/docs/examples/image/preview.vue +37 -0
- package/docs/examples/import-dialog/multiple.vue +35 -0
- package/docs/examples/import-dialog/single.vue +37 -0
- package/docs/examples/independent-nav/icon-slot.vue +7 -0
- package/docs/examples/independent-nav/index.vue +12 -0
- package/docs/examples/input/icon.vue +26 -0
- package/docs/examples/input/index.vue +9 -0
- package/docs/examples/input-number/index.vue +19 -0
- package/docs/examples/layout/gutter.vue +51 -0
- package/docs/examples/layout/index.vue +97 -0
- package/docs/examples/layout/justify.vue +122 -0
- package/docs/examples/layout/mixed.vue +70 -0
- package/docs/examples/layout/offset.vue +70 -0
- package/docs/examples/layout/responsive.vue +69 -0
- package/docs/examples/link/index01.vue +20 -0
- package/docs/examples/link/index02.vue +41 -0
- package/docs/examples/link/index03.vue +43 -0
- package/docs/examples/link/index04.vue +131 -0
- package/docs/examples/mention/index.vue +3 -0
- package/docs/examples/message/closeable.vue +92 -0
- package/docs/examples/message/grouping.vue +22 -0
- package/docs/examples/message/html.vue +21 -0
- package/docs/examples/message/index.vue +34 -0
- package/docs/examples/message/placement.vue +96 -0
- package/docs/examples/message/plain.vue +80 -0
- package/docs/examples/message/types.vue +66 -0
- package/docs/examples/nav/index.vue +20 -0
- package/docs/examples/pagination/background-color.vue +17 -0
- package/docs/examples/pagination/basic.vue +43 -0
- package/docs/examples/pagination/disabled.vue +17 -0
- package/docs/examples/pagination/more.vue +43 -0
- package/docs/examples/pagination/number-of-pagers.vue +17 -0
- package/docs/examples/pagination/small.vue +17 -0
- package/docs/examples/popover/basic.vue +81 -0
- package/docs/examples/popover/index.vue +144 -0
- package/docs/examples/popover/nested.vue +36 -0
- package/docs/examples/popover/rich-content.vue +100 -0
- package/docs/examples/popover/virtual-trigger.vue +32 -0
- package/docs/examples/progress/index.vue +3 -0
- package/docs/examples/radio/basic-usage.vue +44 -0
- package/docs/examples/radio/button-fill-textcolor.vue +82 -0
- package/docs/examples/radio/button-style.vue +77 -0
- package/docs/examples/radio/disabled.vue +21 -0
- package/docs/examples/radio/radio-button-group.vue +13 -0
- package/docs/examples/radio/with-borders.vue +77 -0
- package/docs/examples/result/index.vue +3 -0
- package/docs/examples/scrollbar/horizontal.vue +39 -0
- package/docs/examples/scrollbar/index.vue +31 -0
- package/docs/examples/scrollbar/infinite.vue +43 -0
- package/docs/examples/scrollbar/manual.vue +68 -0
- package/docs/examples/scrollbar/max-height.vue +44 -0
- package/docs/examples/search-panel/index.vue +108 -0
- package/docs/examples/search-panel/nowrap.vue +115 -0
- package/docs/examples/select/allow-create.vue +36 -0
- package/docs/examples/select/clearable.vue +29 -0
- package/docs/examples/select/collapse-tags.vue +54 -0
- package/docs/examples/select/custom-template.vue +40 -0
- package/docs/examples/select/disabled-option.vue +29 -0
- package/docs/examples/select/disabled-select.vue +29 -0
- package/docs/examples/select/empty.vue +21 -0
- package/docs/examples/select/filterable.vue +37 -0
- package/docs/examples/select/grouping.vue +40 -0
- package/docs/examples/select/header-footer.vue +38 -0
- package/docs/examples/select/index.vue +28 -0
- package/docs/examples/select/loading.vue +41 -0
- package/docs/examples/select/multiple-limit.vue +36 -0
- package/docs/examples/select/multiple.vue +37 -0
- package/docs/examples/select/remote-search.vue +56 -0
- package/docs/examples/select/sizes.vue +62 -0
- package/docs/examples/select/value-key.vue +33 -0
- package/docs/examples/slider/index.vue +3 -0
- package/docs/examples/space/alignment.vue +47 -0
- package/docs/examples/space/custom-size.vue +58 -0
- package/docs/examples/space/fill-ratio.vue +77 -0
- package/docs/examples/space/fill.vue +57 -0
- package/docs/examples/space/index.vue +52 -0
- package/docs/examples/space/size.vue +70 -0
- package/docs/examples/space/spacer.vue +35 -0
- package/docs/examples/space/vertical.vue +52 -0
- package/docs/examples/space/wrap.vue +16 -0
- package/docs/examples/steps/index.vue +50 -0
- package/docs/examples/steps/navigation.vue +37 -0
- package/docs/examples/switch/disabled.vue +19 -0
- package/docs/examples/switch/icon.vue +21 -0
- package/docs/examples/switch/index.vue +17 -0
- package/docs/examples/switch/loading.vue +19 -0
- package/docs/examples/switch/size.vue +29 -0
- package/docs/examples/switch/text.vue +37 -0
- package/docs/examples/switch/validate-value.vue +16 -0
- package/docs/examples/table/basic.vue +60 -0
- package/docs/examples/table/check-strictly.vue +98 -0
- package/docs/examples/table/custom-column.vue +98 -0
- package/docs/examples/table/custom-header.vue +87 -0
- package/docs/examples/table/custom-index.vue +71 -0
- package/docs/examples/table/expandable-row.vue +285 -0
- package/docs/examples/table/filter.vue +116 -0
- package/docs/examples/table/fixed-column-and-group-header.vue +101 -0
- package/docs/examples/table/fixed-column-and-header.vue +101 -0
- package/docs/examples/table/fixed-column.vue +107 -0
- package/docs/examples/table/fixed-header-with-fluid-header.vue +114 -0
- package/docs/examples/table/fixed-header.vue +64 -0
- package/docs/examples/table/grouping-header.vue +103 -0
- package/docs/examples/table/multi-select.vue +116 -0
- package/docs/examples/table/rowspan-and-colspan.vue +147 -0
- package/docs/examples/table/show-overflow-tooltip.vue +64 -0
- package/docs/examples/table/single-select.vue +78 -0
- package/docs/examples/table/sort.vue +63 -0
- package/docs/examples/table/striped.vue +49 -0
- package/docs/examples/table/summary.vue +150 -0
- package/docs/examples/table/table-layout.vue +56 -0
- package/docs/examples/table/tooltip-formatter.vue +93 -0
- package/docs/examples/table/tree-and-lazy.vue +149 -0
- package/docs/examples/table/with-border.vue +49 -0
- package/docs/examples/table/with-status.vue +73 -0
- package/docs/examples/table-grid/basic.vue +51 -0
- package/docs/examples/table-grid/complete.vue +258 -0
- package/docs/examples/table-head-editor/grouping-header.vue +409 -0
- package/docs/examples/table-head-editor/index.vue +246 -0
- package/docs/examples/tabs/default.vue +47 -0
- package/docs/examples/tabs/index.vue +46 -0
- package/docs/examples/tag/basic.vue +20 -0
- package/docs/examples/tag/closable.vue +31 -0
- package/docs/examples/tag/dot.vue +21 -0
- package/docs/examples/tag/effect.vue +35 -0
- package/docs/examples/tag/icon.vue +21 -0
- package/docs/examples/text/index.vue +3 -0
- package/docs/examples/time-picker/disabled.vue +53 -0
- package/docs/examples/time-picker/index.vue +49 -0
- package/docs/examples/time-picker/range.vue +36 -0
- package/docs/examples/time-select/disabled.vue +30 -0
- package/docs/examples/time-select/index.vue +29 -0
- package/docs/examples/tooltip/disabled.vue +20 -0
- package/docs/examples/tooltip/index.vue +63 -0
- package/docs/examples/tooltip/more-content.vue +19 -0
- package/docs/examples/tooltip/theme.vue +32 -0
- package/docs/examples/tooltip/virtual-trigger.vue +31 -0
- package/docs/examples/tour/index.vue +3 -0
- package/docs/examples/tree/basic.vue +86 -0
- package/docs/examples/tree/checkable.vue +65 -0
- package/docs/examples/tree/custom-node.vue +123 -0
- package/docs/examples/tree/default-expanded.vue +73 -0
- package/docs/examples/tree/draggable.vue +123 -0
- package/docs/examples/tree/filter.vue +96 -0
- package/docs/examples/tree/index.vue +86 -0
- package/docs/examples/tree-select/basic.vue +96 -0
- package/docs/examples/tree-select/check-strictly.vue +109 -0
- package/docs/examples/tree-select/custom-content.vue +110 -0
- package/docs/examples/tree-select/disabled.vue +89 -0
- package/docs/examples/tree-select/filterable.vue +112 -0
- package/docs/examples/tree-select/index.vue +87 -0
- package/docs/examples/tree-select/lazy.vue +43 -0
- package/docs/examples/tree-select/multiple.vue +111 -0
- package/docs/examples/tree-select/node-key.vue +35 -0
- package/docs/guide/changelog.md +6 -0
- package/docs/guide/import-on-demand.md +49 -0
- package/docs/guide/index.md +55 -0
- package/docs/guide/introduction.md +21 -0
- package/docs/guide/quickstart.md +35 -0
- package/docs/guide/start.md +113 -0
- package/docs/index.md +27 -0
- package/docs/markdown-examples.md +85 -0
- package/docs/package.json +26 -0
- package/docs/postcss.config.mjs +9 -0
- package/docs/toolkit/domain.md +55 -0
- package/docs/toolkit/env.md +73 -0
- package/docs/toolkit/examples/domain-aim.vue +35 -0
- package/docs/toolkit/examples/domain-supplier.vue +34 -0
- package/docs/toolkit/examples/env-basic.vue +28 -0
- package/docs/toolkit/examples/env-constants.vue +39 -0
- package/docs/toolkit/examples/env-node-constants.vue +38 -0
- package/docs/toolkit/examples/env-node.vue +34 -0
- package/docs/toolkit/examples/monitor-init.vue +53 -0
- package/docs/toolkit/examples/monitor-vue-error.vue +31 -0
- package/docs/toolkit/examples/request-baseurl.vue +66 -0
- package/docs/toolkit/examples/request-basic.vue +48 -0
- package/docs/toolkit/examples/request-cache.vue +137 -0
- package/docs/toolkit/examples/wujie-logout.vue +42 -0
- package/docs/toolkit/examples/wujie-token.vue +63 -0
- package/docs/toolkit/monitor.md +69 -0
- package/docs/toolkit/request.md +127 -0
- package/docs/toolkit/start.md +110 -0
- package/docs/toolkit/wujie.md +34 -0
- package/docs/tsconfig.json +29 -0
- package/package.json +47 -0
- package/packages/components/CHANGELOG.md +81 -0
- package/packages/components/README.md +83 -0
- package/packages/components/package.json +36 -0
- package/packages/components/src/action-menu/index.ts +5 -0
- package/packages/components/src/action-menu/src/action-menu.ts +34 -0
- package/packages/components/src/action-menu/src/action-menu.vue +364 -0
- package/packages/components/src/arrow-steps/index.ts +11 -0
- package/packages/components/src/arrow-steps/src/arrow-step.ts +8 -0
- package/packages/components/src/arrow-steps/src/arrow-step.vue +90 -0
- package/packages/components/src/arrow-steps/src/arrow-steps.ts +16 -0
- package/packages/components/src/arrow-steps/src/arrow-steps.vue +42 -0
- package/packages/components/src/badge/index.ts +5 -0
- package/packages/components/src/badge/src/badge.ts +8 -0
- package/packages/components/src/badge/src/badge.vue +20 -0
- package/packages/components/src/batch-copy/index.ts +5 -0
- package/packages/components/src/batch-copy/src/batch-copy.ts +39 -0
- package/packages/components/src/batch-copy/src/batch-copy.vue +214 -0
- package/packages/components/src/batch-editor/index.ts +5 -0
- package/packages/components/src/batch-editor/src/batch-editor.ts +21 -0
- package/packages/components/src/batch-editor/src/batch-editor.vue +73 -0
- package/packages/components/src/border/index.ts +5 -0
- package/packages/components/src/border/src/border.ts +8 -0
- package/packages/components/src/border/src/border.vue +20 -0
- package/packages/components/src/breadcrumb/index.ts +8 -0
- package/packages/components/src/breadcrumb/src/breadcrumb-item.ts +8 -0
- package/packages/components/src/breadcrumb/src/breadcrumb-item.vue +20 -0
- package/packages/components/src/breadcrumb/src/breadcrumb.ts +8 -0
- package/packages/components/src/breadcrumb/src/breadcrumb.vue +20 -0
- package/packages/components/src/button/index.ts +5 -0
- package/packages/components/src/button/src/button.ts +12 -0
- package/packages/components/src/button/src/button.vue +132 -0
- package/packages/components/src/calendar/index.ts +5 -0
- package/packages/components/src/calendar/src/calendar.ts +36 -0
- package/packages/components/src/calendar/src/calendar.vue +962 -0
- package/packages/components/src/card/index.ts +8 -0
- package/packages/components/src/card/src/card.ts +29 -0
- package/packages/components/src/card/src/card.vue +106 -0
- package/packages/components/src/card/src/title.ts +8 -0
- package/packages/components/src/card/src/title.vue +14 -0
- package/packages/components/src/carousel/index.ts +5 -0
- package/packages/components/src/carousel/src/carousel.ts +8 -0
- package/packages/components/src/carousel/src/carousel.vue +20 -0
- package/packages/components/src/cascader/index.ts +5 -0
- package/packages/components/src/cascader/src/cascader.ts +3 -0
- package/packages/components/src/cascader/src/cascader.vue +62 -0
- package/packages/components/src/checkbox/index.ts +11 -0
- package/packages/components/src/checkbox/src/checkbox.vue +19 -0
- package/packages/components/src/collapse/index.ts +5 -0
- package/packages/components/src/collapse/src/collapse.ts +8 -0
- package/packages/components/src/collapse/src/collapse.vue +20 -0
- package/packages/components/src/column-table/index.ts +7 -0
- package/packages/components/src/column-table/src/column-table-row.ts +30 -0
- package/packages/components/src/column-table/src/column-table-row.vue +17 -0
- package/packages/components/src/column-table/src/column-table.ts +60 -0
- package/packages/components/src/column-table/src/column-table.vue +141 -0
- package/packages/components/src/column-table/src/tokens.ts +6 -0
- package/packages/components/src/date-picker/index.ts +5 -0
- package/packages/components/src/date-picker/src/date-picker.ts +3 -0
- package/packages/components/src/date-picker/src/date-picker.vue +14 -0
- package/packages/components/src/demo/index.ts +5 -0
- package/packages/components/src/demo/src/demo.ts +8 -0
- package/packages/components/src/demo/src/demo.vue +20 -0
- package/packages/components/src/description/index.ts +8 -0
- package/packages/components/src/description/src/description-item.ts +12 -0
- package/packages/components/src/description/src/description-item.vue +103 -0
- package/packages/components/src/description/src/description.ts +20 -0
- package/packages/components/src/description/src/description.vue +28 -0
- package/packages/components/src/dialog/index.ts +6 -0
- package/packages/components/src/dialog/src/dialog.ts +62 -0
- package/packages/components/src/dialog/src/dialog.vue +121 -0
- package/packages/components/src/dialog/src/msg-dialog.ts +84 -0
- package/packages/components/src/dialog/src/types.ts +8 -0
- package/packages/components/src/drawer/index.ts +5 -0
- package/packages/components/src/drawer/src/drawer.ts +8 -0
- package/packages/components/src/drawer/src/drawer.vue +24 -0
- package/packages/components/src/editor/index.ts +5 -0
- package/packages/components/src/editor/src/editor.ts +13 -0
- package/packages/components/src/editor/src/editor.vue +70 -0
- package/packages/components/src/empty/index.ts +5 -0
- package/packages/components/src/empty/src/empty.ts +3 -0
- package/packages/components/src/empty/src/empty.vue +37 -0
- package/packages/components/src/empty/src/img-empty.vue +39 -0
- package/packages/components/src/file-task-dialog/index.ts +5 -0
- package/packages/components/src/file-task-dialog/src/file-task-dialog.ts +32 -0
- package/packages/components/src/file-task-dialog/src/file-task-dialog.vue +228 -0
- package/packages/components/src/form/index.ts +3 -0
- package/packages/components/src/icon/index.ts +5 -0
- package/packages/components/src/icon/src/icon.ts +10 -0
- package/packages/components/src/icon/src/icon.vue +29 -0
- package/packages/components/src/image/index.ts +5 -0
- package/packages/components/src/image/src/image.ts +8 -0
- package/packages/components/src/image/src/image.vue +57 -0
- package/packages/components/src/import-dialog/index.ts +5 -0
- package/packages/components/src/import-dialog/src/import-dialog.ts +11 -0
- package/packages/components/src/import-dialog/src/import-dialog.vue +207 -0
- package/packages/components/src/independent-nav/index.ts +5 -0
- package/packages/components/src/independent-nav/src/independent-nav.ts +7 -0
- package/packages/components/src/independent-nav/src/independent-nav.vue +61 -0
- package/packages/components/src/index.ts +235 -0
- package/packages/components/src/input/index.ts +5 -0
- package/packages/components/src/input/src/input.ts +3 -0
- package/packages/components/src/input/src/input.vue +53 -0
- package/packages/components/src/input-number/index.ts +5 -0
- package/packages/components/src/input-number/src/input-number.ts +3 -0
- package/packages/components/src/input-number/src/input-number.vue +25 -0
- package/packages/components/src/layout/index.ts +7 -0
- package/packages/components/src/layout/src/col.vue +43 -0
- package/packages/components/src/layout/src/layout.ts +13 -0
- package/packages/components/src/layout/src/row.vue +43 -0
- package/packages/components/src/link/index.ts +5 -0
- package/packages/components/src/link/src/link.ts +13 -0
- package/packages/components/src/link/src/link.vue +74 -0
- package/packages/components/src/mention/index.ts +5 -0
- package/packages/components/src/mention/src/mention.ts +8 -0
- package/packages/components/src/mention/src/mention.vue +20 -0
- package/packages/components/src/message/index.ts +1 -0
- package/packages/components/src/message/src/message.ts +161 -0
- package/packages/components/src/nav/index.ts +7 -0
- package/packages/components/src/nav/src/nav.ts +19 -0
- package/packages/components/src/nav/src/nav.vue +66 -0
- package/packages/components/src/nav/src/types.ts +11 -0
- package/packages/components/src/pagination/index.ts +5 -0
- package/packages/components/src/pagination/src/pagination.ts +60 -0
- package/packages/components/src/pagination/src/pagination.vue +38 -0
- package/packages/components/src/popover/index.ts +5 -0
- package/packages/components/src/popover/src/popover.ts +14 -0
- package/packages/components/src/popover/src/popover.vue +60 -0
- package/packages/components/src/progress/index.ts +5 -0
- package/packages/components/src/progress/src/progress.ts +8 -0
- package/packages/components/src/progress/src/progress.vue +20 -0
- package/packages/components/src/radio/index.ts +11 -0
- package/packages/components/src/radio/src/radio.vue +13 -0
- package/packages/components/src/result/index.ts +5 -0
- package/packages/components/src/result/src/result.ts +8 -0
- package/packages/components/src/result/src/result.vue +20 -0
- package/packages/components/src/scrollbar/index.ts +5 -0
- package/packages/components/src/scrollbar/src/scrollbar.ts +8 -0
- package/packages/components/src/scrollbar/src/scrollbar.vue +54 -0
- package/packages/components/src/search-panel/index.ts +5 -0
- package/packages/components/src/search-panel/src/search-panel.ts +8 -0
- package/packages/components/src/search-panel/src/search-panel.vue +251 -0
- package/packages/components/src/select/index.ts +9 -0
- package/packages/components/src/select/src/select.ts +3 -0
- package/packages/components/src/select/src/select.vue +43 -0
- package/packages/components/src/slider/index.ts +5 -0
- package/packages/components/src/slider/src/slider.ts +8 -0
- package/packages/components/src/slider/src/slider.vue +20 -0
- package/packages/components/src/space/index.ts +5 -0
- package/packages/components/src/space/src/space.ts +8 -0
- package/packages/components/src/space/src/space.vue +43 -0
- package/packages/components/src/steps/index.ts +8 -0
- package/packages/components/src/steps/src/step.ts +15 -0
- package/packages/components/src/steps/src/step.vue +18 -0
- package/packages/components/src/steps/src/steps.ts +20 -0
- package/packages/components/src/steps/src/steps.vue +95 -0
- package/packages/components/src/steps/src/tokens.ts +6 -0
- package/packages/components/src/switch/index.ts +5 -0
- package/packages/components/src/switch/src/switch.ts +8 -0
- package/packages/components/src/switch/src/switch.vue +51 -0
- package/packages/components/src/table/index.ts +7 -0
- package/packages/components/src/table/src/table.ts +34 -0
- package/packages/components/src/table/src/table.vue +47 -0
- package/packages/components/src/table-grid/index.ts +7 -0
- package/packages/components/src/table-grid/src/render-cell.vue +44 -0
- package/packages/components/src/table-grid/src/table-grid.ts +159 -0
- package/packages/components/src/table-grid/src/table-grid.vue +334 -0
- package/packages/components/src/table-head-editor/index.ts +5 -0
- package/packages/components/src/table-head-editor/src/table-head-editor.ts +59 -0
- package/packages/components/src/table-head-editor/src/table-head-editor.vue +780 -0
- package/packages/components/src/table-head-editor/src/utils.ts +192 -0
- package/packages/components/src/tabs/index.ts +7 -0
- package/packages/components/src/tabs/src/tabs.ts +8 -0
- package/packages/components/src/tabs/src/tabs.vue +23 -0
- package/packages/components/src/tag/index.ts +5 -0
- package/packages/components/src/tag/src/tag.ts +47 -0
- package/packages/components/src/tag/src/tag.vue +60 -0
- package/packages/components/src/tag/src/types.ts +8 -0
- package/packages/components/src/text/index.ts +5 -0
- package/packages/components/src/text/src/text.ts +8 -0
- package/packages/components/src/text/src/text.vue +20 -0
- package/packages/components/src/time-picker/index.ts +5 -0
- package/packages/components/src/time-picker/src/time-picker.ts +3 -0
- package/packages/components/src/time-picker/src/time-picker.vue +14 -0
- package/packages/components/src/time-select/index.ts +5 -0
- package/packages/components/src/time-select/src/time-select.ts +5 -0
- package/packages/components/src/time-select/src/time-select.vue +14 -0
- package/packages/components/src/tooltip/index.ts +5 -0
- package/packages/components/src/tooltip/src/tooltip.ts +6 -0
- package/packages/components/src/tooltip/src/tooltip.vue +71 -0
- package/packages/components/src/tour/index.ts +5 -0
- package/packages/components/src/tour/src/tour.ts +8 -0
- package/packages/components/src/tour/src/tour.vue +20 -0
- package/packages/components/src/tree/index.ts +5 -0
- package/packages/components/src/tree/src/tree.ts +8 -0
- package/packages/components/src/tree/src/tree.vue +77 -0
- package/packages/components/src/tree-select/index.ts +3 -0
- package/packages/components/src/tree-select/src/tree-select.vue +96 -0
- package/packages/components/tsconfig.json +19 -0
- package/packages/components/vite.config.ts +32 -0
- package/packages/icons/CHANGELOG.md +45 -0
- package/packages/icons/README.md +86 -0
- package/packages/icons/package.json +30 -0
- package/packages/icons/src/components/arrow-down.vue +12 -0
- package/packages/icons/src/components/arrow-left.vue +12 -0
- package/packages/icons/src/components/arrow-right.vue +12 -0
- package/packages/icons/src/components/arrow-up.vue +12 -0
- package/packages/icons/src/components/circle-check.vue +15 -0
- package/packages/icons/src/components/circle-close.vue +15 -0
- package/packages/icons/src/components/close.vue +13 -0
- package/packages/icons/src/components/copy.vue +12 -0
- package/packages/icons/src/components/delete.vue +12 -0
- package/packages/icons/src/components/download.vue +15 -0
- package/packages/icons/src/components/edit.vue +12 -0
- package/packages/icons/src/components/error.vue +12 -0
- package/packages/icons/src/components/export.vue +17 -0
- package/packages/icons/src/components/file.vue +21 -0
- package/packages/icons/src/components/import.vue +19 -0
- package/packages/icons/src/components/index.ts +37 -0
- package/packages/icons/src/components/info.vue +13 -0
- package/packages/icons/src/components/list-process.vue +37 -0
- package/packages/icons/src/components/log.vue +17 -0
- package/packages/icons/src/components/minus.vue +13 -0
- package/packages/icons/src/components/money-bubble.vue +21 -0
- package/packages/icons/src/components/plane.vue +30 -0
- package/packages/icons/src/components/plus.vue +17 -0
- package/packages/icons/src/components/printer.vue +17 -0
- package/packages/icons/src/components/reset.vue +21 -0
- package/packages/icons/src/components/right.vue +21 -0
- package/packages/icons/src/components/search.vue +15 -0
- package/packages/icons/src/components/select.vue +17 -0
- package/packages/icons/src/components/semi-select.vue +17 -0
- package/packages/icons/src/components/setting.vue +25 -0
- package/packages/icons/src/components/stamp.vue +35 -0
- package/packages/icons/src/components/success.vue +13 -0
- package/packages/icons/src/components/tree-triangle.vue +17 -0
- package/packages/icons/src/components/upload.vue +21 -0
- package/packages/icons/src/components/view.vue +15 -0
- package/packages/icons/src/components/warning.vue +13 -0
- package/packages/icons/src/components/zoom-in.vue +27 -0
- package/packages/icons/src/components/zoom-out.vue +27 -0
- package/packages/icons/src/index.ts +9 -0
- package/packages/icons/tsconfig.json +10 -0
- package/packages/icons/vite.config.ts +33 -0
- package/packages/styles/CHANGELOG.md +99 -0
- package/packages/styles/README.md +107 -0
- package/packages/styles/package.json +23 -0
- package/packages/styles/src/action-menu.scss +103 -0
- package/packages/styles/src/arrow-step.scss +138 -0
- package/packages/styles/src/arrow-steps.scss +8 -0
- package/packages/styles/src/batch-copy.scss +40 -0
- package/packages/styles/src/batch-editor.scss +36 -0
- package/packages/styles/src/breadcrumb.scss +29 -0
- package/packages/styles/src/button.scss +127 -0
- package/packages/styles/src/calendar.scss +327 -0
- package/packages/styles/src/card.scss +85 -0
- package/packages/styles/src/cascader.scss +59 -0
- package/packages/styles/src/checkbox.scss +46 -0
- package/packages/styles/src/column-table.scss +13 -0
- package/packages/styles/src/date-picker.scss +547 -0
- package/packages/styles/src/description.scss +38 -0
- package/packages/styles/src/dialog.scss +120 -0
- package/packages/styles/src/drawer.scss +22 -0
- package/packages/styles/src/editor.scss +13 -0
- package/packages/styles/src/empty.scss +12 -0
- package/packages/styles/src/file-task-dialog.scss +13 -0
- package/packages/styles/src/image.scss +6 -0
- package/packages/styles/src/import-dialog.scss +122 -0
- package/packages/styles/src/independent-nav.scss +37 -0
- package/packages/styles/src/index.scss +46 -0
- package/packages/styles/src/input-number.scss +34 -0
- package/packages/styles/src/input.scss +28 -0
- package/packages/styles/src/link.scss +70 -0
- package/packages/styles/src/message.scss +12 -0
- package/packages/styles/src/mixins.scss +60 -0
- package/packages/styles/src/nav.scss +12 -0
- package/packages/styles/src/overrides.scss +25 -0
- package/packages/styles/src/pagination.scss +161 -0
- package/packages/styles/src/popover.scss +4 -0
- package/packages/styles/src/radio.scss +54 -0
- package/packages/styles/src/search-panel.scss +51 -0
- package/packages/styles/src/select.scss +44 -0
- package/packages/styles/src/steps.scss +336 -0
- package/packages/styles/src/switch.scss +35 -0
- package/packages/styles/src/table-grid.scss +37 -0
- package/packages/styles/src/table-head-editor.scss +112 -0
- package/packages/styles/src/table.scss +33 -0
- package/packages/styles/src/tabs.scss +45 -0
- package/packages/styles/src/tag.scss +29 -0
- package/packages/styles/src/theme.scss +101 -0
- package/packages/styles/src/time-picker.scss +225 -0
- package/packages/styles/src/time-select.scss +141 -0
- package/packages/styles/src/tooltip.scss +21 -0
- package/packages/styles/src/tree-select.scss +52 -0
- package/packages/styles/src/tree.scss +8 -0
- package/packages/styles/src/utilities.scss +81 -0
- package/packages/styles/src/variables.scss +56 -0
- package/packages/styles/vite.config.ts +28 -0
- package/pnpm-workspace.yaml +3 -0
- package/tsconfig.json +46 -0
package/SETUP_GUIDE.md
ADDED
|
@@ -0,0 +1,2530 @@
|
|
|
1
|
+
# M-Design 组件库初始化完整指南
|
|
2
|
+
|
|
3
|
+
本指南将详细教你如何从零开始创建一个基于 Monorepo 架构的 Vue 3 组件库项目。
|
|
4
|
+
|
|
5
|
+
## 📋 目录
|
|
6
|
+
|
|
7
|
+
1. [项目概述](#项目概述)
|
|
8
|
+
2. [环境准备](#环境准备)
|
|
9
|
+
3. [项目初始化](#项目初始化)
|
|
10
|
+
4. [创建 Monorepo 基础结构](#创建-monorepo-基础结构)
|
|
11
|
+
5. [创建组件包 (components)](#创建组件包-components)
|
|
12
|
+
6. [创建图标包 (icons)](#创建图标包-icons)
|
|
13
|
+
7. [创建样式包 (styles)](#创建样式包-styles)
|
|
14
|
+
8. [创建工具包 (utils)](#创建工具包-utils)
|
|
15
|
+
9. [创建文档站点 (docs)](#创建文档站点-docs)
|
|
16
|
+
10. [测试和验证](#测试和验证)
|
|
17
|
+
11. [打包和发布](#打包和发布)
|
|
18
|
+
- [一、文档站点打包和部署](#一文档站点打包和部署)
|
|
19
|
+
- [二、Packages 打包](#二packages-打包)
|
|
20
|
+
- [三、发布到 npm](#三发布到-npm)
|
|
21
|
+
- [四、CI/CD 自动化发布](#四cicd-自动化发布)
|
|
22
|
+
- [五、发布命令速查表](#五发布命令速查表)
|
|
23
|
+
12. [常见问题](#常见问题)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 项目概述
|
|
28
|
+
|
|
29
|
+
### 项目结构
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
m-design/
|
|
33
|
+
├── packages/ # 所有包的目录
|
|
34
|
+
│ ├── components/ # 组件包
|
|
35
|
+
│ ├── icons/ # 图标包
|
|
36
|
+
│ ├── styles/ # 样式包
|
|
37
|
+
│ └── utils/ # 工具包
|
|
38
|
+
├── docs/ # 文档站点
|
|
39
|
+
├── package.json # 根 package.json
|
|
40
|
+
├── pnpm-workspace.yaml # pnpm workspace 配置
|
|
41
|
+
└── tsconfig.json # TypeScript 配置
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 技术栈
|
|
45
|
+
|
|
46
|
+
- **Vue 3**: 使用 Composition API
|
|
47
|
+
- **TypeScript**: 完整的类型支持
|
|
48
|
+
- **Element Plus**: 基础 UI 组件库
|
|
49
|
+
- **Vite**: 构建工具
|
|
50
|
+
- **SCSS**: 样式预处理器
|
|
51
|
+
- **VitePress**: 文档站点
|
|
52
|
+
- **pnpm**: 包管理器,支持 workspace
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 环境准备
|
|
57
|
+
|
|
58
|
+
### 1. 安装 Node.js
|
|
59
|
+
|
|
60
|
+
确保已安装 Node.js >= 18.0.0
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
node -v
|
|
64
|
+
# 应该显示 v18.x.x 或更高版本
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. 安装 pnpm
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install -g pnpm
|
|
71
|
+
# 或
|
|
72
|
+
npm install -g pnpm@latest
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
验证安装:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm -v
|
|
79
|
+
# 应该显示 8.x.x 或更高版本
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 3. 创建项目目录
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
mkdir m-design
|
|
86
|
+
cd m-design
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 项目初始化
|
|
92
|
+
|
|
93
|
+
### 步骤 1: 初始化根 package.json
|
|
94
|
+
|
|
95
|
+
创建根目录的 `package.json`:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"name": "m-design",
|
|
100
|
+
"version": "1.0.0",
|
|
101
|
+
"description": "后台管理系统前端组件库",
|
|
102
|
+
"private": true,
|
|
103
|
+
"type": "module",
|
|
104
|
+
"scripts": {
|
|
105
|
+
"dev": "pnpm --filter docs dev",
|
|
106
|
+
"build": "pnpm -r --filter './packages/*' build",
|
|
107
|
+
"build:docs": "pnpm --filter docs build",
|
|
108
|
+
"preview:docs": "pnpm --filter docs preview",
|
|
109
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
|
|
110
|
+
"type-check": "pnpm -r --filter './packages/*' type-check"
|
|
111
|
+
},
|
|
112
|
+
"keywords": [
|
|
113
|
+
"vue3",
|
|
114
|
+
"component-library",
|
|
115
|
+
"element-plus",
|
|
116
|
+
"monorepo"
|
|
117
|
+
],
|
|
118
|
+
"author": "",
|
|
119
|
+
"license": "MIT",
|
|
120
|
+
"devDependencies": {
|
|
121
|
+
"@types/node": "^20.10.0",
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
123
|
+
"@typescript-eslint/parser": "^6.15.0",
|
|
124
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
125
|
+
"eslint": "^8.55.0",
|
|
126
|
+
"eslint-plugin-vue": "^9.19.2",
|
|
127
|
+
"sass": "^1.69.5",
|
|
128
|
+
"typescript": "^5.3.3",
|
|
129
|
+
"vite": "^5.0.8",
|
|
130
|
+
"vitepress": "^1.0.0-rc.31",
|
|
131
|
+
"vue-tsc": "^1.8.27"
|
|
132
|
+
},
|
|
133
|
+
"engines": {
|
|
134
|
+
"node": ">=18.0.0",
|
|
135
|
+
"pnpm": ">=8.0.0"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 步骤 2: 创建 pnpm workspace 配置
|
|
141
|
+
|
|
142
|
+
创建 `pnpm-workspace.yaml`:
|
|
143
|
+
|
|
144
|
+
```yaml
|
|
145
|
+
packages:
|
|
146
|
+
- 'packages/*'
|
|
147
|
+
- 'docs'
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 步骤 3: 创建 .npmrc 配置
|
|
151
|
+
|
|
152
|
+
创建 `.npmrc`:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
shamefully-hoist=true
|
|
156
|
+
strict-peer-dependencies=false
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 步骤 4: 创建 TypeScript 配置
|
|
160
|
+
|
|
161
|
+
创建根目录 `tsconfig.json`:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"compilerOptions": {
|
|
166
|
+
"target": "ES2020",
|
|
167
|
+
"useDefineForClassFields": true,
|
|
168
|
+
"module": "ESNext",
|
|
169
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
170
|
+
"skipLibCheck": true,
|
|
171
|
+
"moduleResolution": "bundler",
|
|
172
|
+
"allowImportingTsExtensions": true,
|
|
173
|
+
"resolveJsonModule": true,
|
|
174
|
+
"isolatedModules": true,
|
|
175
|
+
"noEmit": true,
|
|
176
|
+
"jsx": "preserve",
|
|
177
|
+
"strict": true,
|
|
178
|
+
"noUnusedLocals": true,
|
|
179
|
+
"noUnusedParameters": true,
|
|
180
|
+
"noFallthroughCasesInSwitch": true,
|
|
181
|
+
"baseUrl": ".",
|
|
182
|
+
"paths": {
|
|
183
|
+
"@m-design/components": ["./packages/components/src"],
|
|
184
|
+
"@m-design/icons": ["./packages/icons/src"],
|
|
185
|
+
"@m-design/styles": ["./packages/styles/src"],
|
|
186
|
+
"@m-design/utils": ["./packages/utils/src"]
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
"include": ["packages/**/*.ts", "packages/**/*.tsx", "packages/**/*.vue", "docs/**/*.ts", "docs/**/*.vue"],
|
|
190
|
+
"exclude": ["node_modules", "dist"]
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 步骤 5: 创建 .gitignore
|
|
195
|
+
|
|
196
|
+
创建 `.gitignore`:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
# Dependencies
|
|
200
|
+
node_modules
|
|
201
|
+
.pnp
|
|
202
|
+
.pnp.js
|
|
203
|
+
|
|
204
|
+
# Testing
|
|
205
|
+
coverage
|
|
206
|
+
|
|
207
|
+
# Production
|
|
208
|
+
dist
|
|
209
|
+
dist-ssr
|
|
210
|
+
*.local
|
|
211
|
+
|
|
212
|
+
# Editor directories and files
|
|
213
|
+
.vscode/*
|
|
214
|
+
!.vscode/extensions.json
|
|
215
|
+
.idea
|
|
216
|
+
.DS_Store
|
|
217
|
+
*.suo
|
|
218
|
+
*.ntvs*
|
|
219
|
+
*.njsproj
|
|
220
|
+
*.sln
|
|
221
|
+
*.sw?
|
|
222
|
+
|
|
223
|
+
# Logs
|
|
224
|
+
logs
|
|
225
|
+
*.log
|
|
226
|
+
npm-debug.log*
|
|
227
|
+
yarn-debug.log*
|
|
228
|
+
yarn-error.log*
|
|
229
|
+
pnpm-debug.log*
|
|
230
|
+
lerna-debug.log*
|
|
231
|
+
|
|
232
|
+
# Environment
|
|
233
|
+
.env
|
|
234
|
+
.env.local
|
|
235
|
+
.env.*.local
|
|
236
|
+
|
|
237
|
+
# Build
|
|
238
|
+
*.tsbuildinfo
|
|
239
|
+
|
|
240
|
+
# VitePress
|
|
241
|
+
docs/.vitepress/dist
|
|
242
|
+
docs/.vitepress/cache
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 步骤 6: 创建目录结构
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
mkdir -p packages/components/src
|
|
249
|
+
mkdir -p packages/icons/src
|
|
250
|
+
mkdir -p packages/styles/src
|
|
251
|
+
mkdir -p packages/utils/src
|
|
252
|
+
mkdir -p docs
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 步骤 7: 安装依赖
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pnpm install
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## 创建组件包 (components)
|
|
264
|
+
|
|
265
|
+
### 步骤 1: 创建 package.json
|
|
266
|
+
|
|
267
|
+
在 `packages/components/` 目录下创建 `package.json`:
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"name": "@m-design/components",
|
|
272
|
+
"version": "1.0.0",
|
|
273
|
+
"description": "M-Design 组件库",
|
|
274
|
+
"type": "module",
|
|
275
|
+
"main": "./dist/index.js",
|
|
276
|
+
"module": "./dist/index.js",
|
|
277
|
+
"types": "./dist/index.d.ts",
|
|
278
|
+
"exports": {
|
|
279
|
+
".": {
|
|
280
|
+
"import": "./dist/index.js",
|
|
281
|
+
"types": "./dist/index.d.ts"
|
|
282
|
+
},
|
|
283
|
+
"./style": "./dist/style.css"
|
|
284
|
+
},
|
|
285
|
+
"files": [
|
|
286
|
+
"dist"
|
|
287
|
+
],
|
|
288
|
+
"scripts": {
|
|
289
|
+
"build": "vite build && vue-tsc --emitDeclarationOnly --outDir dist",
|
|
290
|
+
"type-check": "vue-tsc --noEmit"
|
|
291
|
+
},
|
|
292
|
+
"peerDependencies": {
|
|
293
|
+
"vue": "^3.3.0",
|
|
294
|
+
"element-plus": "^2.4.0"
|
|
295
|
+
},
|
|
296
|
+
"devDependencies": {
|
|
297
|
+
"@m-design/icons": "workspace:*",
|
|
298
|
+
"@m-design/utils": "workspace:*",
|
|
299
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
300
|
+
"element-plus": "^2.4.0",
|
|
301
|
+
"typescript": "^5.3.3",
|
|
302
|
+
"vue": "^3.3.0",
|
|
303
|
+
"vue-tsc": "^1.8.27",
|
|
304
|
+
"vite": "^5.0.8"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### 步骤 2: 创建 Vite 配置
|
|
310
|
+
|
|
311
|
+
创建 `packages/components/vite.config.ts`:
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import { defineConfig } from 'vite'
|
|
315
|
+
import vue from '@vitejs/plugin-vue'
|
|
316
|
+
import { resolve } from 'path'
|
|
317
|
+
|
|
318
|
+
export default defineConfig({
|
|
319
|
+
plugins: [vue()],
|
|
320
|
+
build: {
|
|
321
|
+
lib: {
|
|
322
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
323
|
+
name: 'MDesign',
|
|
324
|
+
fileName: 'index',
|
|
325
|
+
formats: ['es']
|
|
326
|
+
},
|
|
327
|
+
rollupOptions: {
|
|
328
|
+
external: ['vue', 'element-plus'],
|
|
329
|
+
output: {
|
|
330
|
+
globals: {
|
|
331
|
+
vue: 'Vue',
|
|
332
|
+
'element-plus': 'ElementPlus'
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
cssCodeSplit: false,
|
|
337
|
+
sourcemap: true,
|
|
338
|
+
outDir: 'dist'
|
|
339
|
+
},
|
|
340
|
+
resolve: {
|
|
341
|
+
alias: {
|
|
342
|
+
'@': resolve(__dirname, 'src')
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### 步骤 3: 创建 TypeScript 配置
|
|
349
|
+
|
|
350
|
+
创建 `packages/components/tsconfig.json`:
|
|
351
|
+
|
|
352
|
+
```json
|
|
353
|
+
{
|
|
354
|
+
"extends": "../../tsconfig.json",
|
|
355
|
+
"compilerOptions": {
|
|
356
|
+
"outDir": "./dist",
|
|
357
|
+
"declaration": true,
|
|
358
|
+
"declarationMap": true
|
|
359
|
+
},
|
|
360
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
361
|
+
"exclude": ["node_modules", "dist"]
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### 步骤 4: 创建 Button 组件
|
|
366
|
+
|
|
367
|
+
#### 4.1 创建类型定义
|
|
368
|
+
|
|
369
|
+
创建 `packages/components/src/button/types.ts`:
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
import type { ComponentSize } from 'element-plus'
|
|
373
|
+
|
|
374
|
+
export interface ButtonProps {
|
|
375
|
+
type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text'
|
|
376
|
+
size?: ComponentSize
|
|
377
|
+
plain?: boolean
|
|
378
|
+
round?: boolean
|
|
379
|
+
circle?: boolean
|
|
380
|
+
loading?: boolean
|
|
381
|
+
disabled?: boolean
|
|
382
|
+
icon?: string
|
|
383
|
+
autofocus?: boolean
|
|
384
|
+
nativeType?: 'button' | 'submit' | 'reset'
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
#### 4.2 创建组件文件
|
|
389
|
+
|
|
390
|
+
创建 `packages/components/src/button/button.vue`:
|
|
391
|
+
|
|
392
|
+
```vue
|
|
393
|
+
<template>
|
|
394
|
+
<el-button
|
|
395
|
+
:type="type"
|
|
396
|
+
:size="size"
|
|
397
|
+
:plain="plain"
|
|
398
|
+
:round="round"
|
|
399
|
+
:circle="circle"
|
|
400
|
+
:loading="loading"
|
|
401
|
+
:disabled="disabled"
|
|
402
|
+
:icon="icon"
|
|
403
|
+
:autofocus="autofocus"
|
|
404
|
+
:native-type="nativeType"
|
|
405
|
+
@click="handleClick"
|
|
406
|
+
>
|
|
407
|
+
<slot></slot>
|
|
408
|
+
</el-button>
|
|
409
|
+
</template>
|
|
410
|
+
|
|
411
|
+
<script setup lang="ts">
|
|
412
|
+
import { defineProps, defineEmits } from 'vue'
|
|
413
|
+
import type { ButtonProps } from './types'
|
|
414
|
+
|
|
415
|
+
defineOptions({
|
|
416
|
+
name: 'MButton'
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
const props = withDefaults(defineProps<ButtonProps>(), {
|
|
420
|
+
type: 'default',
|
|
421
|
+
size: 'default',
|
|
422
|
+
plain: false,
|
|
423
|
+
round: false,
|
|
424
|
+
circle: false,
|
|
425
|
+
loading: false,
|
|
426
|
+
disabled: false,
|
|
427
|
+
autofocus: false,
|
|
428
|
+
nativeType: 'button'
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
const emit = defineEmits<{
|
|
432
|
+
click: [event: MouseEvent]
|
|
433
|
+
}>()
|
|
434
|
+
|
|
435
|
+
const handleClick = (event: MouseEvent) => {
|
|
436
|
+
emit('click', event)
|
|
437
|
+
}
|
|
438
|
+
</script>
|
|
439
|
+
|
|
440
|
+
<style scoped lang="scss">
|
|
441
|
+
.m-button {
|
|
442
|
+
// 自定义样式
|
|
443
|
+
}
|
|
444
|
+
</style>
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
#### 4.3 创建导出文件
|
|
448
|
+
|
|
449
|
+
创建 `packages/components/src/button/index.ts`:
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
import MButton from './button.vue'
|
|
453
|
+
import type { App } from 'vue'
|
|
454
|
+
|
|
455
|
+
MButton.install = (app: App) => {
|
|
456
|
+
app.component('MButton', MButton)
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export { MButton }
|
|
460
|
+
export default MButton
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### 步骤 5: 创建 Table 组件
|
|
464
|
+
|
|
465
|
+
#### 5.1 创建类型定义
|
|
466
|
+
|
|
467
|
+
创建 `packages/components/src/table/types.ts`:
|
|
468
|
+
|
|
469
|
+
```typescript
|
|
470
|
+
import type { ComponentSize } from 'element-plus'
|
|
471
|
+
|
|
472
|
+
export interface TableColumn {
|
|
473
|
+
prop?: string
|
|
474
|
+
label?: string
|
|
475
|
+
width?: string | number
|
|
476
|
+
minWidth?: string | number
|
|
477
|
+
fixed?: boolean | 'left' | 'right'
|
|
478
|
+
sortable?: boolean | 'custom'
|
|
479
|
+
align?: 'left' | 'center' | 'right'
|
|
480
|
+
headerAlign?: 'left' | 'center' | 'right'
|
|
481
|
+
slot?: string
|
|
482
|
+
// 可以添加更多属性
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export interface TableProps {
|
|
486
|
+
data?: any[]
|
|
487
|
+
columns?: TableColumn[]
|
|
488
|
+
height?: string | number
|
|
489
|
+
maxHeight?: string | number
|
|
490
|
+
stripe?: boolean
|
|
491
|
+
border?: boolean
|
|
492
|
+
size?: ComponentSize
|
|
493
|
+
fit?: boolean
|
|
494
|
+
showHeader?: boolean
|
|
495
|
+
highlightCurrentRow?: boolean
|
|
496
|
+
emptyText?: string
|
|
497
|
+
// 可以添加更多属性
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### 5.2 创建组件文件
|
|
502
|
+
|
|
503
|
+
创建 `packages/components/src/table/table.vue`:
|
|
504
|
+
|
|
505
|
+
```vue
|
|
506
|
+
<template>
|
|
507
|
+
<el-table
|
|
508
|
+
:data="data"
|
|
509
|
+
:height="height"
|
|
510
|
+
:max-height="maxHeight"
|
|
511
|
+
:stripe="stripe"
|
|
512
|
+
:border="border"
|
|
513
|
+
:size="size"
|
|
514
|
+
:fit="fit"
|
|
515
|
+
:show-header="showHeader"
|
|
516
|
+
:highlight-current-row="highlightCurrentRow"
|
|
517
|
+
:empty-text="emptyText"
|
|
518
|
+
>
|
|
519
|
+
<template v-for="column in columns" :key="column.prop">
|
|
520
|
+
<el-table-column
|
|
521
|
+
:prop="column.prop"
|
|
522
|
+
:label="column.label"
|
|
523
|
+
:width="column.width"
|
|
524
|
+
:min-width="column.minWidth"
|
|
525
|
+
:fixed="column.fixed"
|
|
526
|
+
:sortable="column.sortable"
|
|
527
|
+
:align="column.align"
|
|
528
|
+
:header-align="column.headerAlign"
|
|
529
|
+
>
|
|
530
|
+
<template v-if="column.slot" #default="scope">
|
|
531
|
+
<slot :name="column.slot" :row="scope.row" :column="scope.column" :$index="scope.$index"></slot>
|
|
532
|
+
</template>
|
|
533
|
+
</el-table-column>
|
|
534
|
+
</template>
|
|
535
|
+
<slot></slot>
|
|
536
|
+
</el-table>
|
|
537
|
+
</template>
|
|
538
|
+
|
|
539
|
+
<script setup lang="ts">
|
|
540
|
+
import { defineProps } from 'vue'
|
|
541
|
+
import type { TableProps } from './types'
|
|
542
|
+
|
|
543
|
+
defineOptions({
|
|
544
|
+
name: 'MTable'
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
withDefaults(defineProps<TableProps>(), {
|
|
548
|
+
stripe: false,
|
|
549
|
+
border: false,
|
|
550
|
+
size: 'default',
|
|
551
|
+
fit: true,
|
|
552
|
+
showHeader: true,
|
|
553
|
+
highlightCurrentRow: false,
|
|
554
|
+
emptyText: '暂无数据'
|
|
555
|
+
})
|
|
556
|
+
</script>
|
|
557
|
+
|
|
558
|
+
<style scoped lang="scss">
|
|
559
|
+
.m-table {
|
|
560
|
+
// 自定义样式
|
|
561
|
+
}
|
|
562
|
+
</style>
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
#### 5.3 创建导出文件
|
|
566
|
+
|
|
567
|
+
创建 `packages/components/src/table/index.ts`:
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
import MTable from './table.vue'
|
|
571
|
+
import type { App } from 'vue'
|
|
572
|
+
|
|
573
|
+
MTable.install = (app: App) => {
|
|
574
|
+
app.component('MTable', MTable)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export { MTable }
|
|
578
|
+
export default MTable
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### 步骤 6: 创建主入口文件
|
|
582
|
+
|
|
583
|
+
创建 `packages/components/src/index.ts`:
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
import type { App } from 'vue'
|
|
587
|
+
import { MButton } from './button'
|
|
588
|
+
import { MTable } from './table'
|
|
589
|
+
|
|
590
|
+
// 所有组件
|
|
591
|
+
const components = [
|
|
592
|
+
{ name: 'MButton', component: MButton },
|
|
593
|
+
{ name: 'MTable', component: MTable }
|
|
594
|
+
]
|
|
595
|
+
|
|
596
|
+
// 全量引入
|
|
597
|
+
const install = (app: App) => {
|
|
598
|
+
components.forEach(({ name, component }) => {
|
|
599
|
+
app.component(name, component)
|
|
600
|
+
})
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// 按需引入
|
|
604
|
+
export { MButton, MTable, install }
|
|
605
|
+
|
|
606
|
+
// 默认导出
|
|
607
|
+
export default {
|
|
608
|
+
install
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// 类型导出
|
|
612
|
+
export type { ButtonProps } from './button/types'
|
|
613
|
+
export type { TableProps, TableColumn } from './table/types'
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
---
|
|
617
|
+
|
|
618
|
+
## 创建图标包 (icons)
|
|
619
|
+
|
|
620
|
+
### 步骤 1: 创建 package.json
|
|
621
|
+
|
|
622
|
+
在 `packages/icons/` 目录下创建 `package.json`:
|
|
623
|
+
|
|
624
|
+
```json
|
|
625
|
+
{
|
|
626
|
+
"name": "@m-design/icons",
|
|
627
|
+
"version": "1.0.0",
|
|
628
|
+
"description": "M-Design 图标库",
|
|
629
|
+
"type": "module",
|
|
630
|
+
"main": "./dist/index.js",
|
|
631
|
+
"module": "./dist/index.js",
|
|
632
|
+
"types": "./dist/index.d.ts",
|
|
633
|
+
"exports": {
|
|
634
|
+
".": {
|
|
635
|
+
"import": "./dist/index.js",
|
|
636
|
+
"types": "./dist/index.d.ts"
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
"files": [
|
|
640
|
+
"dist"
|
|
641
|
+
],
|
|
642
|
+
"scripts": {
|
|
643
|
+
"build": "vite build && tsc --emitDeclarationOnly --outDir dist",
|
|
644
|
+
"type-check": "tsc --noEmit"
|
|
645
|
+
},
|
|
646
|
+
"devDependencies": {
|
|
647
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
648
|
+
"typescript": "^5.3.3",
|
|
649
|
+
"vue": "^3.3.0",
|
|
650
|
+
"vite": "^5.0.8"
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### 步骤 2: 创建 Vite 配置
|
|
656
|
+
|
|
657
|
+
创建 `packages/icons/vite.config.ts`:
|
|
658
|
+
|
|
659
|
+
```typescript
|
|
660
|
+
import { defineConfig } from 'vite'
|
|
661
|
+
import vue from '@vitejs/plugin-vue'
|
|
662
|
+
import { resolve } from 'path'
|
|
663
|
+
|
|
664
|
+
export default defineConfig({
|
|
665
|
+
plugins: [vue()],
|
|
666
|
+
build: {
|
|
667
|
+
lib: {
|
|
668
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
669
|
+
name: 'MDesignIcons',
|
|
670
|
+
fileName: 'index',
|
|
671
|
+
formats: ['es']
|
|
672
|
+
},
|
|
673
|
+
rollupOptions: {
|
|
674
|
+
external: ['vue'],
|
|
675
|
+
output: {
|
|
676
|
+
globals: {
|
|
677
|
+
vue: 'Vue'
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
sourcemap: true
|
|
682
|
+
}
|
|
683
|
+
})
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
### 步骤 3: 创建 TypeScript 配置
|
|
687
|
+
|
|
688
|
+
创建 `packages/icons/tsconfig.json`:
|
|
689
|
+
|
|
690
|
+
```json
|
|
691
|
+
{
|
|
692
|
+
"extends": "../../tsconfig.json",
|
|
693
|
+
"compilerOptions": {
|
|
694
|
+
"outDir": "./dist",
|
|
695
|
+
"declaration": true,
|
|
696
|
+
"declarationMap": true
|
|
697
|
+
},
|
|
698
|
+
"include": ["src/**/*.ts", "src/**/*.vue"],
|
|
699
|
+
"exclude": ["node_modules", "dist"]
|
|
700
|
+
}
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
### 步骤 4: 创建图标组件
|
|
704
|
+
|
|
705
|
+
创建 `packages/icons/src/user.vue`:
|
|
706
|
+
|
|
707
|
+
```vue
|
|
708
|
+
<template>
|
|
709
|
+
<svg
|
|
710
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
711
|
+
:width="size"
|
|
712
|
+
:height="size"
|
|
713
|
+
viewBox="0 0 24 24"
|
|
714
|
+
fill="none"
|
|
715
|
+
stroke="currentColor"
|
|
716
|
+
stroke-width="2"
|
|
717
|
+
stroke-linecap="round"
|
|
718
|
+
stroke-linejoin="round"
|
|
719
|
+
>
|
|
720
|
+
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
|
721
|
+
<circle cx="12" cy="7" r="4"></circle>
|
|
722
|
+
</svg>
|
|
723
|
+
</template>
|
|
724
|
+
|
|
725
|
+
<script setup lang="ts">
|
|
726
|
+
withDefaults(
|
|
727
|
+
defineProps<{
|
|
728
|
+
size?: string | number
|
|
729
|
+
}>(),
|
|
730
|
+
{
|
|
731
|
+
size: 16
|
|
732
|
+
}
|
|
733
|
+
)
|
|
734
|
+
</script>
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
创建 `packages/icons/src/setting.vue`:
|
|
738
|
+
|
|
739
|
+
```vue
|
|
740
|
+
<template>
|
|
741
|
+
<svg
|
|
742
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
743
|
+
:width="size"
|
|
744
|
+
:height="size"
|
|
745
|
+
viewBox="0 0 24 24"
|
|
746
|
+
fill="none"
|
|
747
|
+
stroke="currentColor"
|
|
748
|
+
stroke-width="2"
|
|
749
|
+
stroke-linecap="round"
|
|
750
|
+
stroke-linejoin="round"
|
|
751
|
+
>
|
|
752
|
+
<circle cx="12" cy="12" r="3"></circle>
|
|
753
|
+
<path
|
|
754
|
+
d="M12 1v6m0 6v6M5.64 5.64l4.24 4.24m4.24 4.24l4.24 4.24M1 12h6m6 0h6M5.64 18.36l4.24-4.24m4.24-4.24l4.24-4.24"
|
|
755
|
+
></path>
|
|
756
|
+
</svg>
|
|
757
|
+
</template>
|
|
758
|
+
|
|
759
|
+
<script setup lang="ts">
|
|
760
|
+
withDefaults(
|
|
761
|
+
defineProps<{
|
|
762
|
+
size?: string | number
|
|
763
|
+
}>(),
|
|
764
|
+
{
|
|
765
|
+
size: 16
|
|
766
|
+
}
|
|
767
|
+
)
|
|
768
|
+
</script>
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
### 步骤 5: 创建入口文件
|
|
772
|
+
|
|
773
|
+
创建 `packages/icons/src/index.ts`:
|
|
774
|
+
|
|
775
|
+
```typescript
|
|
776
|
+
// 图标组件示例
|
|
777
|
+
export { default as MIconUser } from './user.vue'
|
|
778
|
+
export { default as MIconSetting } from './setting.vue'
|
|
779
|
+
|
|
780
|
+
// 图标名称列表
|
|
781
|
+
export const iconNames = ['user', 'setting'] as const
|
|
782
|
+
|
|
783
|
+
export type IconName = typeof iconNames[number]
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
---
|
|
787
|
+
|
|
788
|
+
## 创建样式包 (styles)
|
|
789
|
+
|
|
790
|
+
### 步骤 1: 创建 package.json
|
|
791
|
+
|
|
792
|
+
在 `packages/styles/` 目录下创建 `package.json`:
|
|
793
|
+
|
|
794
|
+
```json
|
|
795
|
+
{
|
|
796
|
+
"name": "@m-design/styles",
|
|
797
|
+
"version": "1.0.0",
|
|
798
|
+
"description": "M-Design 样式库",
|
|
799
|
+
"type": "module",
|
|
800
|
+
"main": "./dist/index.css",
|
|
801
|
+
"exports": {
|
|
802
|
+
".": "./dist/index.css"
|
|
803
|
+
},
|
|
804
|
+
"files": [
|
|
805
|
+
"dist"
|
|
806
|
+
],
|
|
807
|
+
"scripts": {
|
|
808
|
+
"build": "vite build"
|
|
809
|
+
},
|
|
810
|
+
"devDependencies": {
|
|
811
|
+
"sass": "^1.69.5",
|
|
812
|
+
"vite": "^5.0.8"
|
|
813
|
+
},
|
|
814
|
+
"peerDependencies": {
|
|
815
|
+
"element-plus": "^2.4.0"
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
### 步骤 2: 创建 Vite 配置
|
|
821
|
+
|
|
822
|
+
创建 `packages/styles/vite.config.ts`:
|
|
823
|
+
|
|
824
|
+
```typescript
|
|
825
|
+
import { defineConfig } from 'vite'
|
|
826
|
+
import { resolve } from 'path'
|
|
827
|
+
|
|
828
|
+
export default defineConfig({
|
|
829
|
+
css: {
|
|
830
|
+
preprocessorOptions: {
|
|
831
|
+
scss: {
|
|
832
|
+
additionalData: `@use "${resolve(__dirname, 'src/variables.scss').replace(/\\/g, '/')}" as *;`
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
},
|
|
836
|
+
build: {
|
|
837
|
+
lib: {
|
|
838
|
+
entry: resolve(__dirname, 'src/index.scss'),
|
|
839
|
+
formats: ['es'],
|
|
840
|
+
fileName: 'index'
|
|
841
|
+
},
|
|
842
|
+
rollupOptions: {
|
|
843
|
+
output: {
|
|
844
|
+
assetFileNames: 'index.css'
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
cssCodeSplit: false
|
|
848
|
+
}
|
|
849
|
+
})
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
### 步骤 3: 创建样式变量
|
|
853
|
+
|
|
854
|
+
创建 `packages/styles/src/variables.scss`:
|
|
855
|
+
|
|
856
|
+
```scss
|
|
857
|
+
// 主题色
|
|
858
|
+
$primary-color: #409eff;
|
|
859
|
+
$success-color: #67c23a;
|
|
860
|
+
$warning-color: #e6a23c;
|
|
861
|
+
$danger-color: #f56c6c;
|
|
862
|
+
$info-color: #909399;
|
|
863
|
+
|
|
864
|
+
// 文字颜色
|
|
865
|
+
$text-color-primary: #303133;
|
|
866
|
+
$text-color-regular: #606266;
|
|
867
|
+
$text-color-secondary: #909399;
|
|
868
|
+
$text-color-placeholder: #c0c4cc;
|
|
869
|
+
|
|
870
|
+
// 边框颜色
|
|
871
|
+
$border-color-base: #dcdfe6;
|
|
872
|
+
$border-color-light: #e4e7ed;
|
|
873
|
+
$border-color-lighter: #ebeef5;
|
|
874
|
+
$border-color-extra-light: #f2f6fc;
|
|
875
|
+
|
|
876
|
+
// 背景色
|
|
877
|
+
$bg-color: #ffffff;
|
|
878
|
+
$bg-color-page: #f2f3f5;
|
|
879
|
+
$bg-color-overlay: #ffffff;
|
|
880
|
+
|
|
881
|
+
// 字体大小
|
|
882
|
+
$font-size-extra-large: 20px;
|
|
883
|
+
$font-size-large: 18px;
|
|
884
|
+
$font-size-medium: 16px;
|
|
885
|
+
$font-size-base: 14px;
|
|
886
|
+
$font-size-small: 13px;
|
|
887
|
+
$font-size-extra-small: 12px;
|
|
888
|
+
|
|
889
|
+
// 间距
|
|
890
|
+
$spacing-xs: 4px;
|
|
891
|
+
$spacing-sm: 8px;
|
|
892
|
+
$spacing-md: 16px;
|
|
893
|
+
$spacing-lg: 24px;
|
|
894
|
+
$spacing-xl: 32px;
|
|
895
|
+
|
|
896
|
+
// 圆角
|
|
897
|
+
$border-radius-base: 4px;
|
|
898
|
+
$border-radius-small: 2px;
|
|
899
|
+
$border-radius-round: 20px;
|
|
900
|
+
$border-radius-circle: 100%;
|
|
901
|
+
|
|
902
|
+
// 阴影
|
|
903
|
+
$box-shadow-base: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
|
|
904
|
+
$box-shadow-dark: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.12);
|
|
905
|
+
$box-shadow-light: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
### 步骤 4: 创建样式混入
|
|
909
|
+
|
|
910
|
+
创建 `packages/styles/src/mixins.scss`:
|
|
911
|
+
|
|
912
|
+
```scss
|
|
913
|
+
// 清除浮动
|
|
914
|
+
@mixin clearfix {
|
|
915
|
+
&::after {
|
|
916
|
+
content: '';
|
|
917
|
+
display: table;
|
|
918
|
+
clear: both;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// 文本省略
|
|
923
|
+
@mixin text-ellipsis {
|
|
924
|
+
overflow: hidden;
|
|
925
|
+
text-overflow: ellipsis;
|
|
926
|
+
white-space: nowrap;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// 多行文本省略
|
|
930
|
+
@mixin text-ellipsis-multiline($lines: 2) {
|
|
931
|
+
display: -webkit-box;
|
|
932
|
+
-webkit-box-orient: vertical;
|
|
933
|
+
-webkit-line-clamp: $lines;
|
|
934
|
+
overflow: hidden;
|
|
935
|
+
text-overflow: ellipsis;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// 居中
|
|
939
|
+
@mixin center {
|
|
940
|
+
display: flex;
|
|
941
|
+
align-items: center;
|
|
942
|
+
justify-content: center;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// 垂直居中
|
|
946
|
+
@mixin vertical-center {
|
|
947
|
+
display: flex;
|
|
948
|
+
align-items: center;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// 水平居中
|
|
952
|
+
@mixin horizontal-center {
|
|
953
|
+
display: flex;
|
|
954
|
+
justify-content: center;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// 滚动条样式
|
|
958
|
+
@mixin scrollbar($width: 8px, $thumb-color: #c1c1c1, $track-color: #f1f1f1) {
|
|
959
|
+
&::-webkit-scrollbar {
|
|
960
|
+
width: $width;
|
|
961
|
+
height: $width;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
&::-webkit-scrollbar-thumb {
|
|
965
|
+
background-color: $thumb-color;
|
|
966
|
+
border-radius: 4px;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
&::-webkit-scrollbar-track {
|
|
970
|
+
background-color: $track-color;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
### 步骤 5: 创建样式覆写
|
|
976
|
+
|
|
977
|
+
创建 `packages/styles/src/overrides.scss`:
|
|
978
|
+
|
|
979
|
+
```scss
|
|
980
|
+
// Element Plus 样式覆写
|
|
981
|
+
@use './variables.scss' as *;
|
|
982
|
+
|
|
983
|
+
// 按钮样式覆写
|
|
984
|
+
.el-button {
|
|
985
|
+
// 自定义按钮样式
|
|
986
|
+
&.m-button-custom {
|
|
987
|
+
border-radius: 6px;
|
|
988
|
+
font-weight: 500;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// 表格样式覆写
|
|
993
|
+
.el-table {
|
|
994
|
+
// 自定义表格样式
|
|
995
|
+
&.m-table-custom {
|
|
996
|
+
.el-table__header {
|
|
997
|
+
th {
|
|
998
|
+
background-color: #f5f7fa;
|
|
999
|
+
color: $text-color-primary;
|
|
1000
|
+
font-weight: 600;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
### 步骤 6: 创建工具类
|
|
1008
|
+
|
|
1009
|
+
创建 `packages/styles/src/utilities.scss`:
|
|
1010
|
+
|
|
1011
|
+
```scss
|
|
1012
|
+
// 工具类
|
|
1013
|
+
@use './variables.scss' as *;
|
|
1014
|
+
|
|
1015
|
+
// 间距工具类
|
|
1016
|
+
@for $i from 0 through 10 {
|
|
1017
|
+
.m-mt-#{$i} {
|
|
1018
|
+
margin-top: #{$i * 4}px !important;
|
|
1019
|
+
}
|
|
1020
|
+
.m-mb-#{$i} {
|
|
1021
|
+
margin-bottom: #{$i * 4}px !important;
|
|
1022
|
+
}
|
|
1023
|
+
.m-ml-#{$i} {
|
|
1024
|
+
margin-left: #{$i * 4}px !important;
|
|
1025
|
+
}
|
|
1026
|
+
.m-mr-#{$i} {
|
|
1027
|
+
margin-right: #{$i * 4}px !important;
|
|
1028
|
+
}
|
|
1029
|
+
.m-mx-#{$i} {
|
|
1030
|
+
margin-left: #{$i * 4}px !important;
|
|
1031
|
+
margin-right: #{$i * 4}px !important;
|
|
1032
|
+
}
|
|
1033
|
+
.m-my-#{$i} {
|
|
1034
|
+
margin-top: #{$i * 4}px !important;
|
|
1035
|
+
margin-bottom: #{$i * 4}px !important;
|
|
1036
|
+
}
|
|
1037
|
+
.m-pt-#{$i} {
|
|
1038
|
+
padding-top: #{$i * 4}px !important;
|
|
1039
|
+
}
|
|
1040
|
+
.m-pb-#{$i} {
|
|
1041
|
+
padding-bottom: #{$i * 4}px !important;
|
|
1042
|
+
}
|
|
1043
|
+
.m-pl-#{$i} {
|
|
1044
|
+
padding-left: #{$i * 4}px !important;
|
|
1045
|
+
}
|
|
1046
|
+
.m-pr-#{$i} {
|
|
1047
|
+
padding-right: #{$i * 4}px !important;
|
|
1048
|
+
}
|
|
1049
|
+
.m-px-#{$i} {
|
|
1050
|
+
padding-left: #{$i * 4}px !important;
|
|
1051
|
+
padding-right: #{$i * 4}px !important;
|
|
1052
|
+
}
|
|
1053
|
+
.m-py-#{$i} {
|
|
1054
|
+
padding-top: #{$i * 4}px !important;
|
|
1055
|
+
padding-bottom: #{$i * 4}px !important;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// 文本工具类
|
|
1060
|
+
.m-text-center {
|
|
1061
|
+
text-align: center !important;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
.m-text-left {
|
|
1065
|
+
text-align: left !important;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
.m-text-right {
|
|
1069
|
+
text-align: right !important;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
.m-text-ellipsis {
|
|
1073
|
+
overflow: hidden;
|
|
1074
|
+
text-overflow: ellipsis;
|
|
1075
|
+
white-space: nowrap;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// Flex 工具类
|
|
1079
|
+
.m-flex {
|
|
1080
|
+
display: flex !important;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
.m-flex-center {
|
|
1084
|
+
display: flex !important;
|
|
1085
|
+
align-items: center !important;
|
|
1086
|
+
justify-content: center !important;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
.m-flex-between {
|
|
1090
|
+
display: flex !important;
|
|
1091
|
+
justify-content: space-between !important;
|
|
1092
|
+
}
|
|
1093
|
+
```
|
|
1094
|
+
|
|
1095
|
+
### 步骤 7: 创建主入口文件
|
|
1096
|
+
|
|
1097
|
+
创建 `packages/styles/src/index.scss`:
|
|
1098
|
+
|
|
1099
|
+
```scss
|
|
1100
|
+
// @use 规则必须写在所有其他规则之前
|
|
1101
|
+
// 引入变量(使用 @use 替代 @import)
|
|
1102
|
+
@use './variables.scss' as *;
|
|
1103
|
+
|
|
1104
|
+
// 引入混入(使用 @use 替代 @import)
|
|
1105
|
+
@use './mixins.scss' as *;
|
|
1106
|
+
|
|
1107
|
+
// 引入样式覆写(使用 @use 替代 @import)
|
|
1108
|
+
@use './overrides.scss' as *;
|
|
1109
|
+
|
|
1110
|
+
// 引入工具类(使用 @use 替代 @import)
|
|
1111
|
+
@use './utilities.scss' as *;
|
|
1112
|
+
|
|
1113
|
+
// 注意:Element Plus 的 CSS 需要在单独的地方导入
|
|
1114
|
+
// 因为 Sass 不允许在 @use 之后使用 @import
|
|
1115
|
+
// 请在使用组件库的地方单独导入:@import 'element-plus/dist/index.css';
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
---
|
|
1119
|
+
|
|
1120
|
+
## 创建工具包 (utils)
|
|
1121
|
+
|
|
1122
|
+
### 步骤 1: 创建 package.json
|
|
1123
|
+
|
|
1124
|
+
在 `packages/utils/` 目录下创建 `package.json`:
|
|
1125
|
+
|
|
1126
|
+
```json
|
|
1127
|
+
{
|
|
1128
|
+
"name": "@m-design/utils",
|
|
1129
|
+
"version": "1.0.0",
|
|
1130
|
+
"description": "M-Design 工具方法库",
|
|
1131
|
+
"type": "module",
|
|
1132
|
+
"main": "./dist/index.js",
|
|
1133
|
+
"module": "./dist/index.js",
|
|
1134
|
+
"types": "./dist/index.d.ts",
|
|
1135
|
+
"exports": {
|
|
1136
|
+
".": {
|
|
1137
|
+
"import": "./dist/index.js",
|
|
1138
|
+
"types": "./dist/index.d.ts"
|
|
1139
|
+
}
|
|
1140
|
+
},
|
|
1141
|
+
"files": [
|
|
1142
|
+
"dist"
|
|
1143
|
+
],
|
|
1144
|
+
"scripts": {
|
|
1145
|
+
"build": "vite build && tsc --emitDeclarationOnly --outDir dist",
|
|
1146
|
+
"type-check": "tsc --noEmit"
|
|
1147
|
+
},
|
|
1148
|
+
"devDependencies": {
|
|
1149
|
+
"typescript": "^5.3.3",
|
|
1150
|
+
"vite": "^5.0.8"
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
### 步骤 2: 创建 Vite 配置
|
|
1156
|
+
|
|
1157
|
+
创建 `packages/utils/vite.config.ts`:
|
|
1158
|
+
|
|
1159
|
+
```typescript
|
|
1160
|
+
import { defineConfig } from 'vite'
|
|
1161
|
+
import { resolve } from 'path'
|
|
1162
|
+
|
|
1163
|
+
export default defineConfig({
|
|
1164
|
+
build: {
|
|
1165
|
+
lib: {
|
|
1166
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
1167
|
+
name: 'MDesignUtils',
|
|
1168
|
+
fileName: 'index',
|
|
1169
|
+
formats: ['es']
|
|
1170
|
+
},
|
|
1171
|
+
sourcemap: true
|
|
1172
|
+
}
|
|
1173
|
+
})
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
### 步骤 3: 创建 TypeScript 配置
|
|
1177
|
+
|
|
1178
|
+
创建 `packages/utils/tsconfig.json`:
|
|
1179
|
+
|
|
1180
|
+
```json
|
|
1181
|
+
{
|
|
1182
|
+
"extends": "../../tsconfig.json",
|
|
1183
|
+
"compilerOptions": {
|
|
1184
|
+
"outDir": "./dist",
|
|
1185
|
+
"declaration": true,
|
|
1186
|
+
"declarationMap": true
|
|
1187
|
+
},
|
|
1188
|
+
"include": ["src/**/*.ts"],
|
|
1189
|
+
"exclude": ["node_modules", "dist"]
|
|
1190
|
+
}
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
### 步骤 4: 创建工具方法
|
|
1194
|
+
|
|
1195
|
+
创建 `packages/utils/src/date.ts`:
|
|
1196
|
+
|
|
1197
|
+
```typescript
|
|
1198
|
+
/**
|
|
1199
|
+
* 日期格式化
|
|
1200
|
+
*/
|
|
1201
|
+
export function formatDate(
|
|
1202
|
+
date: Date | number | string,
|
|
1203
|
+
format: string = 'YYYY-MM-DD HH:mm:ss'
|
|
1204
|
+
): string {
|
|
1205
|
+
const d = typeof date === 'number' || typeof date === 'string' ? new Date(date) : date
|
|
1206
|
+
|
|
1207
|
+
if (isNaN(d.getTime())) {
|
|
1208
|
+
return ''
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
const year = d.getFullYear()
|
|
1212
|
+
const month = String(d.getMonth() + 1).padStart(2, '0')
|
|
1213
|
+
const day = String(d.getDate()).padStart(2, '0')
|
|
1214
|
+
const hours = String(d.getHours()).padStart(2, '0')
|
|
1215
|
+
const minutes = String(d.getMinutes()).padStart(2, '0')
|
|
1216
|
+
const seconds = String(d.getSeconds()).padStart(2, '0')
|
|
1217
|
+
|
|
1218
|
+
return format
|
|
1219
|
+
.replace('YYYY', String(year))
|
|
1220
|
+
.replace('MM', month)
|
|
1221
|
+
.replace('DD', day)
|
|
1222
|
+
.replace('HH', hours)
|
|
1223
|
+
.replace('mm', minutes)
|
|
1224
|
+
.replace('ss', seconds)
|
|
1225
|
+
}
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
创建 `packages/utils/src/format.ts`:
|
|
1229
|
+
|
|
1230
|
+
```typescript
|
|
1231
|
+
/**
|
|
1232
|
+
* 格式化文件大小
|
|
1233
|
+
*/
|
|
1234
|
+
export function formatFileSize(bytes: number): string {
|
|
1235
|
+
if (bytes === 0) return '0 B'
|
|
1236
|
+
const k = 1024
|
|
1237
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
1238
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
1239
|
+
return `${Number((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* 格式化数字(添加千分位)
|
|
1244
|
+
*/
|
|
1245
|
+
export function formatNumber(num: number | string, decimals: number = 0): string {
|
|
1246
|
+
const n = typeof num === 'string' ? parseFloat(num) : num
|
|
1247
|
+
if (isNaN(n)) return '0'
|
|
1248
|
+
return n.toFixed(decimals).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
1249
|
+
}
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
创建 `packages/utils/src/validate.ts`:
|
|
1253
|
+
|
|
1254
|
+
```typescript
|
|
1255
|
+
/**
|
|
1256
|
+
* 验证手机号
|
|
1257
|
+
*/
|
|
1258
|
+
export function validatePhone(phone: string): boolean {
|
|
1259
|
+
const reg = /^1[3-9]\d{9}$/
|
|
1260
|
+
return reg.test(phone)
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* 验证邮箱
|
|
1265
|
+
*/
|
|
1266
|
+
export function validateEmail(email: string): boolean {
|
|
1267
|
+
const reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
|
|
1268
|
+
return reg.test(email)
|
|
1269
|
+
}
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
创建 `packages/utils/src/storage.ts`:
|
|
1273
|
+
|
|
1274
|
+
```typescript
|
|
1275
|
+
/**
|
|
1276
|
+
* LocalStorage 操作
|
|
1277
|
+
*/
|
|
1278
|
+
export const localStorage = {
|
|
1279
|
+
set(key: string, value: any): void {
|
|
1280
|
+
try {
|
|
1281
|
+
window.localStorage.setItem(key, JSON.stringify(value))
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
console.error('LocalStorage set error:', error)
|
|
1284
|
+
}
|
|
1285
|
+
},
|
|
1286
|
+
|
|
1287
|
+
get<T = any>(key: string, defaultValue?: T): T | null {
|
|
1288
|
+
try {
|
|
1289
|
+
const value = window.localStorage.getItem(key)
|
|
1290
|
+
return value ? JSON.parse(value) : defaultValue ?? null
|
|
1291
|
+
} catch (error) {
|
|
1292
|
+
console.error('LocalStorage get error:', error)
|
|
1293
|
+
return defaultValue ?? null
|
|
1294
|
+
}
|
|
1295
|
+
},
|
|
1296
|
+
|
|
1297
|
+
remove(key: string): void {
|
|
1298
|
+
try {
|
|
1299
|
+
window.localStorage.removeItem(key)
|
|
1300
|
+
} catch (error) {
|
|
1301
|
+
console.error('LocalStorage remove error:', error)
|
|
1302
|
+
}
|
|
1303
|
+
},
|
|
1304
|
+
|
|
1305
|
+
clear(): void {
|
|
1306
|
+
try {
|
|
1307
|
+
window.localStorage.clear()
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
console.error('LocalStorage clear error:', error)
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
```
|
|
1314
|
+
|
|
1315
|
+
创建 `packages/utils/src/common.ts`:
|
|
1316
|
+
|
|
1317
|
+
```typescript
|
|
1318
|
+
/**
|
|
1319
|
+
* 深拷贝
|
|
1320
|
+
*/
|
|
1321
|
+
export function deepClone<T>(obj: T): T {
|
|
1322
|
+
if (obj === null || typeof obj !== 'object') return obj
|
|
1323
|
+
if (obj instanceof Date) return new Date(obj.getTime()) as any
|
|
1324
|
+
if (obj instanceof Array) return obj.map((item) => deepClone(item)) as any
|
|
1325
|
+
if (typeof obj === 'object') {
|
|
1326
|
+
const copy: any = {}
|
|
1327
|
+
Object.keys(obj).forEach((key) => {
|
|
1328
|
+
copy[key] = deepClone((obj as any)[key])
|
|
1329
|
+
})
|
|
1330
|
+
return copy
|
|
1331
|
+
}
|
|
1332
|
+
return obj
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* 防抖
|
|
1337
|
+
*/
|
|
1338
|
+
export function debounce<T extends (...args: any[]) => any>(
|
|
1339
|
+
func: T,
|
|
1340
|
+
wait: number = 300
|
|
1341
|
+
): (...args: Parameters<T>) => void {
|
|
1342
|
+
let timeout: ReturnType<typeof setTimeout> | null = null
|
|
1343
|
+
|
|
1344
|
+
return function (this: any, ...args: Parameters<T>) {
|
|
1345
|
+
if (timeout) clearTimeout(timeout)
|
|
1346
|
+
timeout = setTimeout(() => {
|
|
1347
|
+
func.apply(this, args)
|
|
1348
|
+
}, wait)
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
```
|
|
1352
|
+
|
|
1353
|
+
### 步骤 5: 创建入口文件
|
|
1354
|
+
|
|
1355
|
+
创建 `packages/utils/src/index.ts`:
|
|
1356
|
+
|
|
1357
|
+
```typescript
|
|
1358
|
+
// 日期工具
|
|
1359
|
+
export * from './date'
|
|
1360
|
+
|
|
1361
|
+
// 格式化工具
|
|
1362
|
+
export * from './format'
|
|
1363
|
+
|
|
1364
|
+
// 验证工具
|
|
1365
|
+
export * from './validate'
|
|
1366
|
+
|
|
1367
|
+
// 存储工具
|
|
1368
|
+
export * from './storage'
|
|
1369
|
+
|
|
1370
|
+
// 其他工具
|
|
1371
|
+
export * from './common'
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
---
|
|
1375
|
+
|
|
1376
|
+
## 创建文档站点 (docs)
|
|
1377
|
+
|
|
1378
|
+
### 步骤 1: 创建 package.json
|
|
1379
|
+
|
|
1380
|
+
在 `docs/` 目录下创建 `package.json`:
|
|
1381
|
+
|
|
1382
|
+
```json
|
|
1383
|
+
{
|
|
1384
|
+
"name": "@m-design/docs",
|
|
1385
|
+
"version": "1.0.0",
|
|
1386
|
+
"description": "M-Design 文档站点",
|
|
1387
|
+
"type": "module",
|
|
1388
|
+
"scripts": {
|
|
1389
|
+
"dev": "vitepress dev",
|
|
1390
|
+
"build": "vitepress build",
|
|
1391
|
+
"preview": "vitepress preview"
|
|
1392
|
+
},
|
|
1393
|
+
"devDependencies": {
|
|
1394
|
+
"@m-design/components": "workspace:*",
|
|
1395
|
+
"@m-design/icons": "workspace:*",
|
|
1396
|
+
"@m-design/styles": "workspace:*",
|
|
1397
|
+
"@m-design/utils": "workspace:*",
|
|
1398
|
+
"element-plus": "^2.4.0",
|
|
1399
|
+
"vue": "^3.3.0",
|
|
1400
|
+
"vitepress": "^1.0.0-rc.31"
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
```
|
|
1404
|
+
|
|
1405
|
+
```
|
|
1406
|
+
安装 VitePress 与依赖
|
|
1407
|
+
pnpm add -D vitepress vue @vitejs/plugin-vue
|
|
1408
|
+
一键生成 VitePress 骨架(官方脚手架)
|
|
1409
|
+
pnpm dlx vitepress init docs
|
|
1410
|
+
┌ Where to put docs? → docs
|
|
1411
|
+
┌ Site title → My UI
|
|
1412
|
+
┌ Site description → Vue3 组件库
|
|
1413
|
+
┌ Theme → Default Theme
|
|
1414
|
+
┌ Use TypeScript → Yes
|
|
1415
|
+
┌ Add VitePress npm scripts → Yes
|
|
1416
|
+
```
|
|
1417
|
+
### 步骤 2: 创建 VitePress 配置
|
|
1418
|
+
|
|
1419
|
+
创建 `docs/.vitepress/config.ts`:
|
|
1420
|
+
|
|
1421
|
+
```typescript
|
|
1422
|
+
import { defineConfig } from 'vitepress'
|
|
1423
|
+
import { resolve } from 'path'
|
|
1424
|
+
|
|
1425
|
+
export default defineConfig({
|
|
1426
|
+
title: 'M-Design',
|
|
1427
|
+
description: '后台管理系统前端组件库',
|
|
1428
|
+
base: '/',
|
|
1429
|
+
head: [
|
|
1430
|
+
['link', { rel: 'icon', href: '/favicon.ico' }]
|
|
1431
|
+
],
|
|
1432
|
+
markdown: {
|
|
1433
|
+
lineNumbers: false
|
|
1434
|
+
},
|
|
1435
|
+
themeConfig: {
|
|
1436
|
+
nav: [
|
|
1437
|
+
{ text: '指南', link: '/guide/introduction' },
|
|
1438
|
+
{ text: '组件', link: '/components/button' },
|
|
1439
|
+
{ text: '图标', link: '/icons/' },
|
|
1440
|
+
{ text: '工具', link: '/utils/' },
|
|
1441
|
+
{ text: '样式', link: '/styles/' }
|
|
1442
|
+
],
|
|
1443
|
+
sidebar: {
|
|
1444
|
+
'/guide/': [
|
|
1445
|
+
{
|
|
1446
|
+
text: '开始',
|
|
1447
|
+
items: [
|
|
1448
|
+
{ text: '介绍', link: '/guide/introduction' },
|
|
1449
|
+
{ text: '快速开始', link: '/guide/quickstart' },
|
|
1450
|
+
{ text: '按需引入', link: '/guide/import-on-demand' }
|
|
1451
|
+
]
|
|
1452
|
+
}
|
|
1453
|
+
],
|
|
1454
|
+
'/components/': [
|
|
1455
|
+
{
|
|
1456
|
+
text: '基础组件',
|
|
1457
|
+
items: [
|
|
1458
|
+
{ text: 'Button 按钮', link: '/components/button' },
|
|
1459
|
+
{ text: 'Table 表格', link: '/components/table' }
|
|
1460
|
+
]
|
|
1461
|
+
}
|
|
1462
|
+
]
|
|
1463
|
+
},
|
|
1464
|
+
socialLinks: [
|
|
1465
|
+
{ icon: 'github', link: 'https://github.com' }
|
|
1466
|
+
],
|
|
1467
|
+
footer: {
|
|
1468
|
+
message: 'Released under the MIT License.',
|
|
1469
|
+
copyright: 'Copyright © 2024 M-Design'
|
|
1470
|
+
}
|
|
1471
|
+
},
|
|
1472
|
+
vite: {
|
|
1473
|
+
resolve: {
|
|
1474
|
+
alias: {
|
|
1475
|
+
'@m-design/components': resolve(__dirname, '../../packages/components/src'),
|
|
1476
|
+
'@m-design/icons': resolve(__dirname, '../../packages/icons/src'),
|
|
1477
|
+
'@m-design/styles': resolve(__dirname, '../../packages/styles/src'),
|
|
1478
|
+
'@m-design/utils': resolve(__dirname, '../../packages/utils/src')
|
|
1479
|
+
}
|
|
1480
|
+
},
|
|
1481
|
+
css: {
|
|
1482
|
+
preprocessorOptions: {
|
|
1483
|
+
scss: {
|
|
1484
|
+
additionalData: `@use "${resolve(__dirname, '../../packages/styles/src/variables.scss').replace(/\\/g, '/')}" as *;`
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
optimizeDeps: {
|
|
1489
|
+
include: ['element-plus']
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
})
|
|
1493
|
+
```
|
|
1494
|
+
|
|
1495
|
+
### 步骤 3: 创建主题配置
|
|
1496
|
+
|
|
1497
|
+
创建 `docs/.vitepress/theme/index.ts`:
|
|
1498
|
+
|
|
1499
|
+
```typescript
|
|
1500
|
+
import DefaultTheme from 'vitepress/theme'
|
|
1501
|
+
import type { Theme } from 'vitepress'
|
|
1502
|
+
import ElementPlus from 'element-plus'
|
|
1503
|
+
import 'element-plus/dist/index.css'
|
|
1504
|
+
import MDesign from '@m-design/components'
|
|
1505
|
+
import '@m-design/styles/index.scss'
|
|
1506
|
+
import './style.css'
|
|
1507
|
+
|
|
1508
|
+
export default {
|
|
1509
|
+
extends: DefaultTheme,
|
|
1510
|
+
enhanceApp({ app }) {
|
|
1511
|
+
app.use(ElementPlus)
|
|
1512
|
+
app.use(MDesign)
|
|
1513
|
+
}
|
|
1514
|
+
} satisfies Theme
|
|
1515
|
+
```
|
|
1516
|
+
|
|
1517
|
+
创建 `docs/.vitepress/theme/style.css`:
|
|
1518
|
+
|
|
1519
|
+
```css
|
|
1520
|
+
:root {
|
|
1521
|
+
--vp-c-brand: #409eff;
|
|
1522
|
+
--vp-c-brand-light: #66b1ff;
|
|
1523
|
+
--vp-c-brand-lighter: #85c1ff;
|
|
1524
|
+
--vp-c-brand-dark: #337ecc;
|
|
1525
|
+
--vp-c-brand-darker: #2b6cb0;
|
|
1526
|
+
}
|
|
1527
|
+
```
|
|
1528
|
+
|
|
1529
|
+
### 步骤 4: 创建 TypeScript 配置
|
|
1530
|
+
|
|
1531
|
+
创建 `docs/tsconfig.json`:
|
|
1532
|
+
|
|
1533
|
+
```json
|
|
1534
|
+
{
|
|
1535
|
+
"extends": "../tsconfig.json",
|
|
1536
|
+
"compilerOptions": {
|
|
1537
|
+
"baseUrl": "..",
|
|
1538
|
+
"paths": {
|
|
1539
|
+
"@m-design/components": ["./packages/components/src"],
|
|
1540
|
+
"@m-design/icons": ["./packages/icons/src"],
|
|
1541
|
+
"@m-design/styles": ["./packages/styles/src"],
|
|
1542
|
+
"@m-design/utils": ["./packages/utils/src"]
|
|
1543
|
+
},
|
|
1544
|
+
"types": ["vitepress/client"]
|
|
1545
|
+
},
|
|
1546
|
+
"include": [
|
|
1547
|
+
".vitepress/**/*.ts",
|
|
1548
|
+
".vitepress/**/*.vue",
|
|
1549
|
+
"**/*.md"
|
|
1550
|
+
],
|
|
1551
|
+
"exclude": ["node_modules", "dist"]
|
|
1552
|
+
}
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
### 步骤 5: 创建文档页面
|
|
1556
|
+
|
|
1557
|
+
创建 `docs/index.md`:
|
|
1558
|
+
|
|
1559
|
+
```markdown
|
|
1560
|
+
---
|
|
1561
|
+
layout: home
|
|
1562
|
+
|
|
1563
|
+
hero:
|
|
1564
|
+
name: M-Design
|
|
1565
|
+
text: 后台管理系统组件库
|
|
1566
|
+
tagline: 基于 Vue 3 + TypeScript + Element Plus 构建
|
|
1567
|
+
actions:
|
|
1568
|
+
- theme: brand
|
|
1569
|
+
text: 快速开始
|
|
1570
|
+
link: /guide/quickstart
|
|
1571
|
+
- theme: alt
|
|
1572
|
+
text: 查看组件
|
|
1573
|
+
link: /components/button
|
|
1574
|
+
|
|
1575
|
+
features:
|
|
1576
|
+
- icon: ⚡️
|
|
1577
|
+
title: 快速开发
|
|
1578
|
+
details: 基于 Vue 3 Composition API,提供完整的 TypeScript 类型支持
|
|
1579
|
+
- icon: 🎨
|
|
1580
|
+
title: 主题定制
|
|
1581
|
+
details: 支持样式变量定制和 Element Plus 样式覆写
|
|
1582
|
+
- icon: 📦
|
|
1583
|
+
title: 按需引入
|
|
1584
|
+
details: 支持全量引入和按需引入,减少打包体积
|
|
1585
|
+
- icon: 🔧
|
|
1586
|
+
title: 工具丰富
|
|
1587
|
+
details: 提供丰富的工具方法库,包括日期、格式化、验证等
|
|
1588
|
+
---
|
|
1589
|
+
```
|
|
1590
|
+
|
|
1591
|
+
创建 `docs/guide/introduction.md`:
|
|
1592
|
+
|
|
1593
|
+
```markdown
|
|
1594
|
+
# 介绍
|
|
1595
|
+
|
|
1596
|
+
M-Design 是一个基于 Vue 3 + TypeScript + Element Plus 构建的后台管理系统前端组件库。
|
|
1597
|
+
|
|
1598
|
+
## 特性
|
|
1599
|
+
|
|
1600
|
+
- 🎯 **基于 Vue 3**:使用 Composition API,提供更好的 TypeScript 支持
|
|
1601
|
+
- 📦 **Monorepo 架构**:使用 pnpm workspace 管理多包项目
|
|
1602
|
+
- 🎨 **主题定制**:支持样式变量定制和 Element Plus 样式覆写
|
|
1603
|
+
- 📱 **按需引入**:支持全量引入和按需引入,减少打包体积
|
|
1604
|
+
- 🔧 **工具丰富**:提供日期、格式化、验证、存储等工具方法
|
|
1605
|
+
- 📚 **文档完善**:使用 VitePress 构建完整的文档站点
|
|
1606
|
+
|
|
1607
|
+
## 技术栈
|
|
1608
|
+
|
|
1609
|
+
- Vue 3
|
|
1610
|
+
- TypeScript
|
|
1611
|
+
- Element Plus
|
|
1612
|
+
- Vite
|
|
1613
|
+
- SCSS
|
|
1614
|
+
- VitePress
|
|
1615
|
+
```
|
|
1616
|
+
|
|
1617
|
+
创建 `docs/guide/quickstart.md`:
|
|
1618
|
+
|
|
1619
|
+
```markdown
|
|
1620
|
+
# 快速开始
|
|
1621
|
+
|
|
1622
|
+
## 安装
|
|
1623
|
+
|
|
1624
|
+
使用 pnpm 安装:
|
|
1625
|
+
|
|
1626
|
+
\`\`\`bash
|
|
1627
|
+
pnpm add @m-design/components @m-design/styles element-plus
|
|
1628
|
+
\`\`\`
|
|
1629
|
+
|
|
1630
|
+
## 全量引入
|
|
1631
|
+
|
|
1632
|
+
在 \`main.ts\` 中引入:
|
|
1633
|
+
|
|
1634
|
+
\`\`\`typescript
|
|
1635
|
+
import { createApp } from 'vue'
|
|
1636
|
+
import ElementPlus from 'element-plus'
|
|
1637
|
+
import 'element-plus/dist/index.css'
|
|
1638
|
+
import MDesign from '@m-design/components'
|
|
1639
|
+
import '@m-design/styles'
|
|
1640
|
+
import App from './App.vue'
|
|
1641
|
+
|
|
1642
|
+
const app = createApp(App)
|
|
1643
|
+
app.use(ElementPlus)
|
|
1644
|
+
app.use(MDesign)
|
|
1645
|
+
app.mount('#app')
|
|
1646
|
+
\`\`\`
|
|
1647
|
+
|
|
1648
|
+
## 按需引入
|
|
1649
|
+
|
|
1650
|
+
\`\`\`typescript
|
|
1651
|
+
import 'element-plus/dist/index.css'
|
|
1652
|
+
import { MButton, MTable } from '@m-design/components'
|
|
1653
|
+
import '@m-design/styles'
|
|
1654
|
+
\`\`\`
|
|
1655
|
+
```
|
|
1656
|
+
|
|
1657
|
+
创建 `docs/components/button.md`:
|
|
1658
|
+
|
|
1659
|
+
```markdown
|
|
1660
|
+
# Button 按钮
|
|
1661
|
+
|
|
1662
|
+
按钮用于触发一个操作。
|
|
1663
|
+
|
|
1664
|
+
## 基础用法
|
|
1665
|
+
|
|
1666
|
+
基础的按钮用法。
|
|
1667
|
+
|
|
1668
|
+
\`\`\`vue
|
|
1669
|
+
<template>
|
|
1670
|
+
<MButton>默认按钮</MButton>
|
|
1671
|
+
<MButton type="primary">主要按钮</MButton>
|
|
1672
|
+
<MButton type="success">成功按钮</MButton>
|
|
1673
|
+
</template>
|
|
1674
|
+
\`\`\`
|
|
1675
|
+
|
|
1676
|
+
## API
|
|
1677
|
+
|
|
1678
|
+
### Props
|
|
1679
|
+
|
|
1680
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
1681
|
+
| --- | --- | --- | --- |
|
|
1682
|
+
| type | 类型 | \`'default' \| 'primary' \| 'success'\` | \`'default'\` |
|
|
1683
|
+
| size | 尺寸 | \`'large' \| 'default' \| 'small'\` | \`'default'\` |
|
|
1684
|
+
```
|
|
1685
|
+
|
|
1686
|
+
---
|
|
1687
|
+
|
|
1688
|
+
## 测试和验证
|
|
1689
|
+
|
|
1690
|
+
### 步骤 1: 安装所有依赖
|
|
1691
|
+
|
|
1692
|
+
```bash
|
|
1693
|
+
pnpm install
|
|
1694
|
+
```
|
|
1695
|
+
|
|
1696
|
+
### 步骤 2: 启动文档站点
|
|
1697
|
+
|
|
1698
|
+
```bash
|
|
1699
|
+
pnpm dev
|
|
1700
|
+
```
|
|
1701
|
+
|
|
1702
|
+
访问 `http://localhost:5173` 查看文档站点。
|
|
1703
|
+
|
|
1704
|
+
### 步骤 3: 构建所有包
|
|
1705
|
+
|
|
1706
|
+
```bash
|
|
1707
|
+
pnpm build
|
|
1708
|
+
```
|
|
1709
|
+
|
|
1710
|
+
### 步骤 4: 构建文档站点
|
|
1711
|
+
|
|
1712
|
+
```bash
|
|
1713
|
+
pnpm build:docs
|
|
1714
|
+
```
|
|
1715
|
+
|
|
1716
|
+
构建完成后,文档站点会生成在 `docs/.vitepress/dist` 目录下。
|
|
1717
|
+
|
|
1718
|
+
---
|
|
1719
|
+
|
|
1720
|
+
## 打包和发布
|
|
1721
|
+
|
|
1722
|
+
### 一、文档站点打包和部署
|
|
1723
|
+
|
|
1724
|
+
#### 1.1 打包文档站点
|
|
1725
|
+
|
|
1726
|
+
文档站点使用 VitePress 构建,打包命令:
|
|
1727
|
+
|
|
1728
|
+
```bash
|
|
1729
|
+
# 在项目根目录执行
|
|
1730
|
+
pnpm build:docs
|
|
1731
|
+
```
|
|
1732
|
+
|
|
1733
|
+
或者进入 docs 目录执行:
|
|
1734
|
+
|
|
1735
|
+
```bash
|
|
1736
|
+
cd docs
|
|
1737
|
+
pnpm build
|
|
1738
|
+
```
|
|
1739
|
+
|
|
1740
|
+
**打包输出位置**:`docs/.vitepress/dist`
|
|
1741
|
+
|
|
1742
|
+
**打包内容**:
|
|
1743
|
+
- 所有 Markdown 文件编译后的 HTML
|
|
1744
|
+
- 静态资源(图片、字体等)
|
|
1745
|
+
- JavaScript 和 CSS 文件
|
|
1746
|
+
|
|
1747
|
+
#### 1.2 本地预览打包结果
|
|
1748
|
+
|
|
1749
|
+
在发布前,可以先本地预览打包后的结果:
|
|
1750
|
+
|
|
1751
|
+
```bash
|
|
1752
|
+
# 在项目根目录执行
|
|
1753
|
+
pnpm preview:docs
|
|
1754
|
+
```
|
|
1755
|
+
|
|
1756
|
+
或者:
|
|
1757
|
+
|
|
1758
|
+
```bash
|
|
1759
|
+
cd docs
|
|
1760
|
+
pnpm preview
|
|
1761
|
+
```
|
|
1762
|
+
|
|
1763
|
+
访问 `http://localhost:4173` 查看预览效果。
|
|
1764
|
+
|
|
1765
|
+
#### 1.3 部署到服务器
|
|
1766
|
+
|
|
1767
|
+
##### 方式一:使用 Nginx 部署
|
|
1768
|
+
|
|
1769
|
+
**步骤 1:将打包文件上传到服务器**
|
|
1770
|
+
|
|
1771
|
+
```bash
|
|
1772
|
+
# 在本地打包
|
|
1773
|
+
pnpm build:docs
|
|
1774
|
+
|
|
1775
|
+
# 使用 scp 上传到服务器(替换为你的服务器信息)
|
|
1776
|
+
scp -r docs/.vitepress/dist/* user@your-server:/var/www/m-design/
|
|
1777
|
+
|
|
1778
|
+
# 或使用 rsync
|
|
1779
|
+
rsync -avz docs/.vitepress/dist/ user@your-server:/var/www/m-design/
|
|
1780
|
+
```
|
|
1781
|
+
|
|
1782
|
+
**步骤 2:配置 Nginx**
|
|
1783
|
+
|
|
1784
|
+
在服务器上创建 Nginx 配置文件 `/etc/nginx/sites-available/m-design`:
|
|
1785
|
+
|
|
1786
|
+
```nginx
|
|
1787
|
+
server {
|
|
1788
|
+
listen 80;
|
|
1789
|
+
server_name your-domain.com; # 替换为你的域名
|
|
1790
|
+
|
|
1791
|
+
root /var/www/m-design;
|
|
1792
|
+
index index.html;
|
|
1793
|
+
|
|
1794
|
+
location / {
|
|
1795
|
+
try_files $uri $uri/ /index.html;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
# 静态资源缓存
|
|
1799
|
+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
1800
|
+
expires 1y;
|
|
1801
|
+
add_header Cache-Control "public, immutable";
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
```
|
|
1805
|
+
|
|
1806
|
+
**步骤 3:启用配置并重启 Nginx**
|
|
1807
|
+
|
|
1808
|
+
```bash
|
|
1809
|
+
# 创建软链接
|
|
1810
|
+
sudo ln -s /etc/nginx/sites-available/m-design /etc/nginx/sites-enabled/
|
|
1811
|
+
|
|
1812
|
+
# 测试配置
|
|
1813
|
+
sudo nginx -t
|
|
1814
|
+
|
|
1815
|
+
# 重启 Nginx
|
|
1816
|
+
sudo systemctl restart nginx
|
|
1817
|
+
```
|
|
1818
|
+
|
|
1819
|
+
|
|
1820
|
+
### 二、Packages 打包
|
|
1821
|
+
|
|
1822
|
+
#### 2.1 打包所有包
|
|
1823
|
+
|
|
1824
|
+
在项目根目录执行:
|
|
1825
|
+
|
|
1826
|
+
```bash
|
|
1827
|
+
pnpm build
|
|
1828
|
+
```
|
|
1829
|
+
|
|
1830
|
+
这个命令会依次构建 `packages` 目录下的所有包。
|
|
1831
|
+
|
|
1832
|
+
**打包输出位置**:
|
|
1833
|
+
- `packages/components/dist/` - 组件包
|
|
1834
|
+
- `packages/icons/dist/` - 图标包
|
|
1835
|
+
- `packages/styles/dist/` - 样式包
|
|
1836
|
+
- `packages/utils/dist/` - 工具包
|
|
1837
|
+
|
|
1838
|
+
#### 2.2 单独打包某个包
|
|
1839
|
+
|
|
1840
|
+
```bash
|
|
1841
|
+
# 只打包组件包
|
|
1842
|
+
pnpm --filter @m-design/components build
|
|
1843
|
+
|
|
1844
|
+
# 只打包图标包
|
|
1845
|
+
pnpm --filter @m-design/icons build
|
|
1846
|
+
|
|
1847
|
+
# 只打包样式包
|
|
1848
|
+
pnpm --filter @m-design/styles build
|
|
1849
|
+
|
|
1850
|
+
# 只打包工具包
|
|
1851
|
+
pnpm --filter @m-design/utils build
|
|
1852
|
+
```
|
|
1853
|
+
|
|
1854
|
+
#### 2.3 打包产物说明
|
|
1855
|
+
|
|
1856
|
+
**组件包 (`@m-design/components`)**:
|
|
1857
|
+
- `dist/index.js` - ES 模块入口
|
|
1858
|
+
- `dist/index.d.ts` - TypeScript 类型定义
|
|
1859
|
+
- `dist/style.css` - 样式文件(如果有)
|
|
1860
|
+
|
|
1861
|
+
**图标包 (`@m-design/icons`)**:
|
|
1862
|
+
- `dist/index.js` - ES 模块入口
|
|
1863
|
+
- `dist/index.d.ts` - TypeScript 类型定义
|
|
1864
|
+
|
|
1865
|
+
**样式包 (`@m-design/styles`)**:
|
|
1866
|
+
- `dist/index.css` - 编译后的 CSS 文件
|
|
1867
|
+
|
|
1868
|
+
**工具包 (`@m-design/utils`)**:
|
|
1869
|
+
- `dist/index.js` - ES 模块入口
|
|
1870
|
+
- `dist/index.d.ts` - TypeScript 类型定义
|
|
1871
|
+
|
|
1872
|
+
---
|
|
1873
|
+
|
|
1874
|
+
### 三、发布到 npm
|
|
1875
|
+
|
|
1876
|
+
#### 3.1 准备工作
|
|
1877
|
+
|
|
1878
|
+
##### 步骤 1:注册 npm 账号
|
|
1879
|
+
|
|
1880
|
+
如果还没有 npm 账号,访问 [npmjs.com](https://www.npmjs.com/) 注册。
|
|
1881
|
+
|
|
1882
|
+
##### 步骤 2:登录 npm
|
|
1883
|
+
|
|
1884
|
+
```bash
|
|
1885
|
+
npm login
|
|
1886
|
+
```
|
|
1887
|
+
|
|
1888
|
+
输入你的用户名、密码和邮箱。
|
|
1889
|
+
|
|
1890
|
+
##### 步骤 3:检查登录状态
|
|
1891
|
+
|
|
1892
|
+
```bash
|
|
1893
|
+
npm whoami
|
|
1894
|
+
```
|
|
1895
|
+
|
|
1896
|
+
##### 步骤 4:检查包名是否可用
|
|
1897
|
+
|
|
1898
|
+
在发布前,检查包名是否已被占用:
|
|
1899
|
+
|
|
1900
|
+
```bash
|
|
1901
|
+
# 检查组件包
|
|
1902
|
+
npm view @m-design/components
|
|
1903
|
+
|
|
1904
|
+
# 检查图标包
|
|
1905
|
+
npm view @m-design/icons
|
|
1906
|
+
|
|
1907
|
+
# 检查样式包
|
|
1908
|
+
npm view @m-design/styles
|
|
1909
|
+
|
|
1910
|
+
# 检查工具包
|
|
1911
|
+
npm view @m-design/utils
|
|
1912
|
+
```
|
|
1913
|
+
|
|
1914
|
+
如果包名已被占用,需要修改 `package.json` 中的 `name` 字段。
|
|
1915
|
+
|
|
1916
|
+
#### 3.2 配置发布信息
|
|
1917
|
+
|
|
1918
|
+
##### 创建 .npmignore 文件(可选)
|
|
1919
|
+
|
|
1920
|
+
如果不想使用 `package.json` 中的 `files` 字段,可以创建 `.npmignore` 文件来控制发布内容。
|
|
1921
|
+
|
|
1922
|
+
**组件包 (`packages/components/.npmignore`)**:
|
|
1923
|
+
|
|
1924
|
+
```
|
|
1925
|
+
# 源代码(不发布)
|
|
1926
|
+
src/
|
|
1927
|
+
*.vue
|
|
1928
|
+
*.ts
|
|
1929
|
+
!*.d.ts
|
|
1930
|
+
|
|
1931
|
+
# 配置文件
|
|
1932
|
+
tsconfig.json
|
|
1933
|
+
vite.config.ts
|
|
1934
|
+
*.config.*
|
|
1935
|
+
|
|
1936
|
+
# 开发文件
|
|
1937
|
+
README.md
|
|
1938
|
+
.eslintrc.*
|
|
1939
|
+
.prettierrc.*
|
|
1940
|
+
|
|
1941
|
+
# 测试文件
|
|
1942
|
+
test/
|
|
1943
|
+
tests/
|
|
1944
|
+
*.test.*
|
|
1945
|
+
*.spec.*
|
|
1946
|
+
|
|
1947
|
+
# 其他
|
|
1948
|
+
node_modules/
|
|
1949
|
+
.git/
|
|
1950
|
+
.DS_Store
|
|
1951
|
+
```
|
|
1952
|
+
|
|
1953
|
+
**注意**:如果使用了 `package.json` 中的 `files` 字段,`.npmignore` 会被忽略。
|
|
1954
|
+
|
|
1955
|
+
##### 为每个包添加发布配置
|
|
1956
|
+
|
|
1957
|
+
**组件包 (`packages/components/package.json`)**:
|
|
1958
|
+
|
|
1959
|
+
```json
|
|
1960
|
+
{
|
|
1961
|
+
"name": "@your-org/components", // 替换为你的组织名或用户名
|
|
1962
|
+
"version": "1.0.0",
|
|
1963
|
+
"description": "M-Design 组件库",
|
|
1964
|
+
"author": "Your Name <your-email@example.com>",
|
|
1965
|
+
"license": "MIT",
|
|
1966
|
+
"repository": {
|
|
1967
|
+
"type": "git",
|
|
1968
|
+
"url": "https://github.com/your-username/m-design.git",
|
|
1969
|
+
"directory": "packages/components"
|
|
1970
|
+
},
|
|
1971
|
+
"keywords": [
|
|
1972
|
+
"vue3",
|
|
1973
|
+
"component-library",
|
|
1974
|
+
"element-plus"
|
|
1975
|
+
],
|
|
1976
|
+
"publishConfig": {
|
|
1977
|
+
"access": "public" // 如果是 scoped package,需要设置为 public
|
|
1978
|
+
},
|
|
1979
|
+
// ... 其他配置
|
|
1980
|
+
}
|
|
1981
|
+
```
|
|
1982
|
+
|
|
1983
|
+
**图标包 (`packages/icons/package.json`)**:
|
|
1984
|
+
|
|
1985
|
+
```json
|
|
1986
|
+
{
|
|
1987
|
+
"name": "@your-org/icons",
|
|
1988
|
+
"version": "1.0.0",
|
|
1989
|
+
"description": "M-Design 图标库",
|
|
1990
|
+
"author": "Your Name <your-email@example.com>",
|
|
1991
|
+
"license": "MIT",
|
|
1992
|
+
"repository": {
|
|
1993
|
+
"type": "git",
|
|
1994
|
+
"url": "https://github.com/your-username/m-design.git",
|
|
1995
|
+
"directory": "packages/icons"
|
|
1996
|
+
},
|
|
1997
|
+
"keywords": [
|
|
1998
|
+
"vue3",
|
|
1999
|
+
"icons",
|
|
2000
|
+
"svg"
|
|
2001
|
+
],
|
|
2002
|
+
"publishConfig": {
|
|
2003
|
+
"access": "public"
|
|
2004
|
+
},
|
|
2005
|
+
// ... 其他配置
|
|
2006
|
+
}
|
|
2007
|
+
```
|
|
2008
|
+
|
|
2009
|
+
**样式包 (`packages/styles/package.json`)**:
|
|
2010
|
+
|
|
2011
|
+
```json
|
|
2012
|
+
{
|
|
2013
|
+
"name": "@your-org/styles",
|
|
2014
|
+
"version": "1.0.0",
|
|
2015
|
+
"description": "M-Design 样式库",
|
|
2016
|
+
"author": "Your Name <your-email@example.com>",
|
|
2017
|
+
"license": "MIT",
|
|
2018
|
+
"repository": {
|
|
2019
|
+
"type": "git",
|
|
2020
|
+
"url": "https://github.com/your-username/m-design.git",
|
|
2021
|
+
"directory": "packages/styles"
|
|
2022
|
+
},
|
|
2023
|
+
"keywords": [
|
|
2024
|
+
"vue3",
|
|
2025
|
+
"styles",
|
|
2026
|
+
"scss",
|
|
2027
|
+
"css"
|
|
2028
|
+
],
|
|
2029
|
+
"publishConfig": {
|
|
2030
|
+
"access": "public"
|
|
2031
|
+
},
|
|
2032
|
+
// ... 其他配置
|
|
2033
|
+
}
|
|
2034
|
+
```
|
|
2035
|
+
|
|
2036
|
+
**工具包 (`packages/utils/package.json`)**:
|
|
2037
|
+
|
|
2038
|
+
```json
|
|
2039
|
+
{
|
|
2040
|
+
"name": "@your-org/utils",
|
|
2041
|
+
"version": "1.0.0",
|
|
2042
|
+
"description": "M-Design 工具方法库",
|
|
2043
|
+
"author": "Your Name <your-email@example.com>",
|
|
2044
|
+
"license": "MIT",
|
|
2045
|
+
"repository": {
|
|
2046
|
+
"type": "git",
|
|
2047
|
+
"url": "https://github.com/your-username/m-design.git",
|
|
2048
|
+
"directory": "packages/utils"
|
|
2049
|
+
},
|
|
2050
|
+
"keywords": [
|
|
2051
|
+
"vue3",
|
|
2052
|
+
"utils",
|
|
2053
|
+
"utilities"
|
|
2054
|
+
],
|
|
2055
|
+
"publishConfig": {
|
|
2056
|
+
"access": "public"
|
|
2057
|
+
},
|
|
2058
|
+
// ... 其他配置
|
|
2059
|
+
}
|
|
2060
|
+
```
|
|
2061
|
+
|
|
2062
|
+
#### 3.3 发布流程
|
|
2063
|
+
|
|
2064
|
+
##### 方式一:手动发布(推荐首次发布)
|
|
2065
|
+
|
|
2066
|
+
**步骤 1:构建所有包**
|
|
2067
|
+
|
|
2068
|
+
```bash
|
|
2069
|
+
pnpm build
|
|
2070
|
+
```
|
|
2071
|
+
|
|
2072
|
+
**步骤 2:进入要发布的包目录并发布**
|
|
2073
|
+
|
|
2074
|
+
```bash
|
|
2075
|
+
# 发布组件包
|
|
2076
|
+
cd packages/components
|
|
2077
|
+
npm publish
|
|
2078
|
+
|
|
2079
|
+
# 发布图标包
|
|
2080
|
+
cd ../icons
|
|
2081
|
+
npm publish
|
|
2082
|
+
|
|
2083
|
+
# 发布样式包
|
|
2084
|
+
cd ../styles
|
|
2085
|
+
npm publish
|
|
2086
|
+
|
|
2087
|
+
# 发布工具包
|
|
2088
|
+
cd ../utils
|
|
2089
|
+
npm publish
|
|
2090
|
+
```
|
|
2091
|
+
|
|
2092
|
+
##### 方式二:使用 pnpm 批量发布
|
|
2093
|
+
|
|
2094
|
+
**步骤 1:安装发布工具**
|
|
2095
|
+
|
|
2096
|
+
```bash
|
|
2097
|
+
pnpm add -D -w changeset @changesets/cli
|
|
2098
|
+
```
|
|
2099
|
+
|
|
2100
|
+
**步骤 2:初始化 changeset**
|
|
2101
|
+
|
|
2102
|
+
```bash
|
|
2103
|
+
pnpm changeset init
|
|
2104
|
+
```
|
|
2105
|
+
|
|
2106
|
+
这会在项目根目录创建 `.changeset` 目录。
|
|
2107
|
+
|
|
2108
|
+
**步骤 3:添加变更说明**
|
|
2109
|
+
|
|
2110
|
+
```bash
|
|
2111
|
+
pnpm changeset
|
|
2112
|
+
```
|
|
2113
|
+
|
|
2114
|
+
按照提示选择要发布的包和版本类型(patch/minor/major)。
|
|
2115
|
+
|
|
2116
|
+
**步骤 4:更新版本并发布**
|
|
2117
|
+
|
|
2118
|
+
```bash
|
|
2119
|
+
# 更新版本号
|
|
2120
|
+
pnpm changeset version
|
|
2121
|
+
|
|
2122
|
+
# 发布
|
|
2123
|
+
pnpm changeset publish
|
|
2124
|
+
```
|
|
2125
|
+
|
|
2126
|
+
##### 方式三:使用脚本批量发布
|
|
2127
|
+
|
|
2128
|
+
在根目录 `package.json` 中添加发布脚本:
|
|
2129
|
+
|
|
2130
|
+
```json
|
|
2131
|
+
{
|
|
2132
|
+
"scripts": {
|
|
2133
|
+
"publish:components": "cd packages/components && npm publish",
|
|
2134
|
+
"publish:icons": "cd packages/icons && npm publish",
|
|
2135
|
+
"publish:styles": "cd packages/styles && npm publish",
|
|
2136
|
+
"publish:utils": "cd packages/utils && npm publish",
|
|
2137
|
+
"publish:all": "pnpm build && pnpm publish:components && pnpm publish:icons && pnpm publish:styles && pnpm publish:utils"
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
```
|
|
2141
|
+
|
|
2142
|
+
然后执行:
|
|
2143
|
+
|
|
2144
|
+
```bash
|
|
2145
|
+
pnpm publish:all
|
|
2146
|
+
```
|
|
2147
|
+
|
|
2148
|
+
#### 3.4 版本管理
|
|
2149
|
+
|
|
2150
|
+
##### 语义化版本(Semantic Versioning)
|
|
2151
|
+
|
|
2152
|
+
版本号格式:`主版本号.次版本号.修订号`(如 `1.0.0`)
|
|
2153
|
+
|
|
2154
|
+
- **主版本号(Major)**:不兼容的 API 修改
|
|
2155
|
+
- **次版本号(Minor)**:向下兼容的功能性新增
|
|
2156
|
+
- **修订号(Patch)**:向下兼容的问题修正
|
|
2157
|
+
|
|
2158
|
+
##### 更新版本号
|
|
2159
|
+
|
|
2160
|
+
**手动更新**:
|
|
2161
|
+
|
|
2162
|
+
编辑对应包的 `package.json`,修改 `version` 字段。
|
|
2163
|
+
|
|
2164
|
+
**使用 npm version 命令**:
|
|
2165
|
+
|
|
2166
|
+
```bash
|
|
2167
|
+
cd packages/components
|
|
2168
|
+
|
|
2169
|
+
# 修订号 +1
|
|
2170
|
+
npm version patch
|
|
2171
|
+
|
|
2172
|
+
# 次版本号 +1
|
|
2173
|
+
npm version minor
|
|
2174
|
+
|
|
2175
|
+
# 主版本号 +1
|
|
2176
|
+
npm version major
|
|
2177
|
+
```
|
|
2178
|
+
|
|
2179
|
+
这会自动更新 `package.json` 的版本号,并创建一个 git tag。
|
|
2180
|
+
|
|
2181
|
+
#### 3.5 发布检查清单
|
|
2182
|
+
|
|
2183
|
+
发布前请确认:
|
|
2184
|
+
|
|
2185
|
+
- [ ] 所有包都已正确构建(`pnpm build`)
|
|
2186
|
+
- [ ] 版本号已更新
|
|
2187
|
+
- [ ] `package.json` 中的信息完整(name, description, author, repository 等)
|
|
2188
|
+
- [ ] `README.md` 文件存在且内容完整
|
|
2189
|
+
- [ ] `LICENSE` 文件存在
|
|
2190
|
+
- [ ] `.npmignore` 或 `files` 字段配置正确,只发布必要文件
|
|
2191
|
+
- [ ] 已登录 npm(`npm whoami`)
|
|
2192
|
+
- [ ] 包名未被占用
|
|
2193
|
+
|
|
2194
|
+
#### 3.6 发布后验证
|
|
2195
|
+
|
|
2196
|
+
**步骤 1:检查包是否发布成功**
|
|
2197
|
+
|
|
2198
|
+
```bash
|
|
2199
|
+
npm view @your-org/components
|
|
2200
|
+
npm view @your-org/icons
|
|
2201
|
+
npm view @your-org/styles
|
|
2202
|
+
npm view @your-org/utils
|
|
2203
|
+
```
|
|
2204
|
+
|
|
2205
|
+
**步骤 2:测试安装**
|
|
2206
|
+
|
|
2207
|
+
创建一个测试项目:
|
|
2208
|
+
|
|
2209
|
+
```bash
|
|
2210
|
+
mkdir test-install
|
|
2211
|
+
cd test-install
|
|
2212
|
+
pnpm init
|
|
2213
|
+
pnpm add @your-org/components @your-org/styles element-plus
|
|
2214
|
+
```
|
|
2215
|
+
|
|
2216
|
+
**步骤 3:测试使用**
|
|
2217
|
+
|
|
2218
|
+
创建 `test.js`:
|
|
2219
|
+
|
|
2220
|
+
```javascript
|
|
2221
|
+
import { MButton } from '@your-org/components'
|
|
2222
|
+
import '@your-org/styles'
|
|
2223
|
+
console.log('安装成功!', MButton)
|
|
2224
|
+
```
|
|
2225
|
+
|
|
2226
|
+
#### 3.7 更新已发布的包
|
|
2227
|
+
|
|
2228
|
+
**步骤 1:修改代码并构建**
|
|
2229
|
+
|
|
2230
|
+
```bash
|
|
2231
|
+
# 修改代码后
|
|
2232
|
+
pnpm build
|
|
2233
|
+
```
|
|
2234
|
+
|
|
2235
|
+
**步骤 2:更新版本号**
|
|
2236
|
+
|
|
2237
|
+
```bash
|
|
2238
|
+
cd packages/components
|
|
2239
|
+
npm version patch # 或 minor, major
|
|
2240
|
+
```
|
|
2241
|
+
|
|
2242
|
+
**步骤 3:发布新版本**
|
|
2243
|
+
|
|
2244
|
+
```bash
|
|
2245
|
+
npm publish
|
|
2246
|
+
```
|
|
2247
|
+
|
|
2248
|
+
**步骤 4:推送 git tag(如果使用了 npm version)**
|
|
2249
|
+
|
|
2250
|
+
```bash
|
|
2251
|
+
git push
|
|
2252
|
+
git push --tags
|
|
2253
|
+
```
|
|
2254
|
+
|
|
2255
|
+
#### 3.8 撤销发布(不推荐)
|
|
2256
|
+
|
|
2257
|
+
如果发布了错误版本,可以在 72 小时内撤销:
|
|
2258
|
+
|
|
2259
|
+
```bash
|
|
2260
|
+
# 撤销指定版本
|
|
2261
|
+
npm unpublish @your-org/components@1.0.1
|
|
2262
|
+
|
|
2263
|
+
# 撤销整个包(24小时内)
|
|
2264
|
+
npm unpublish @your-org/components --force
|
|
2265
|
+
```
|
|
2266
|
+
|
|
2267
|
+
**注意**:撤销发布会影响使用该版本的用户,请谨慎操作。
|
|
2268
|
+
|
|
2269
|
+
---
|
|
2270
|
+
|
|
2271
|
+
### 四、CI/CD 自动化发布
|
|
2272
|
+
|
|
2273
|
+
#### 4.1 使用 GitHub Actions 自动发布
|
|
2274
|
+
|
|
2275
|
+
创建 `.github/workflows/publish.yml`:
|
|
2276
|
+
|
|
2277
|
+
```yaml
|
|
2278
|
+
name: Publish to npm
|
|
2279
|
+
|
|
2280
|
+
on:
|
|
2281
|
+
push:
|
|
2282
|
+
tags:
|
|
2283
|
+
- 'v*' # 当推送以 v 开头的 tag 时触发
|
|
2284
|
+
|
|
2285
|
+
jobs:
|
|
2286
|
+
publish:
|
|
2287
|
+
runs-on: ubuntu-latest
|
|
2288
|
+
steps:
|
|
2289
|
+
- uses: actions/checkout@v3
|
|
2290
|
+
|
|
2291
|
+
- name: Setup pnpm
|
|
2292
|
+
uses: pnpm/action-setup@v2
|
|
2293
|
+
with:
|
|
2294
|
+
version: 8
|
|
2295
|
+
|
|
2296
|
+
- name: Setup Node.js
|
|
2297
|
+
uses: actions/setup-node@v3
|
|
2298
|
+
with:
|
|
2299
|
+
node-version: 18
|
|
2300
|
+
cache: 'pnpm'
|
|
2301
|
+
registry-url: 'https://registry.npmjs.org'
|
|
2302
|
+
|
|
2303
|
+
- name: Install dependencies
|
|
2304
|
+
run: pnpm install
|
|
2305
|
+
|
|
2306
|
+
- name: Build packages
|
|
2307
|
+
run: pnpm build
|
|
2308
|
+
|
|
2309
|
+
- name: Publish components
|
|
2310
|
+
working-directory: ./packages/components
|
|
2311
|
+
run: npm publish
|
|
2312
|
+
env:
|
|
2313
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
2314
|
+
|
|
2315
|
+
- name: Publish icons
|
|
2316
|
+
working-directory: ./packages/icons
|
|
2317
|
+
run: npm publish
|
|
2318
|
+
env:
|
|
2319
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
2320
|
+
|
|
2321
|
+
- name: Publish styles
|
|
2322
|
+
working-directory: ./packages/styles
|
|
2323
|
+
run: npm publish
|
|
2324
|
+
env:
|
|
2325
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
2326
|
+
|
|
2327
|
+
- name: Publish utils
|
|
2328
|
+
working-directory: ./packages/utils
|
|
2329
|
+
run: npm publish
|
|
2330
|
+
env:
|
|
2331
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
2332
|
+
```
|
|
2333
|
+
|
|
2334
|
+
**配置 NPM_TOKEN**:
|
|
2335
|
+
|
|
2336
|
+
1. 在 npm 上创建 Access Token:
|
|
2337
|
+
- 访问 https://www.npmjs.com/settings/your-username/tokens
|
|
2338
|
+
- 点击 "Generate New Token"
|
|
2339
|
+
- 选择 "Automation" 类型
|
|
2340
|
+
- 复制生成的 token
|
|
2341
|
+
|
|
2342
|
+
2. 在 GitHub 仓库添加 Secret:
|
|
2343
|
+
- 进入仓库 Settings > Secrets and variables > Actions
|
|
2344
|
+
- 点击 "New repository secret"
|
|
2345
|
+
- Name: `NPM_TOKEN`
|
|
2346
|
+
- Value: 粘贴刚才复制的 token
|
|
2347
|
+
|
|
2348
|
+
**发布流程**:
|
|
2349
|
+
|
|
2350
|
+
```bash
|
|
2351
|
+
# 1. 更新版本号
|
|
2352
|
+
cd packages/components
|
|
2353
|
+
npm version patch # 或 minor, major
|
|
2354
|
+
|
|
2355
|
+
# 2. 提交并推送 tag
|
|
2356
|
+
git push
|
|
2357
|
+
git push --tags
|
|
2358
|
+
|
|
2359
|
+
# 3. GitHub Actions 会自动发布到 npm
|
|
2360
|
+
```
|
|
2361
|
+
|
|
2362
|
+
#### 4.2 使用 changesets 自动化发布
|
|
2363
|
+
|
|
2364
|
+
**安装 changesets**:
|
|
2365
|
+
|
|
2366
|
+
```bash
|
|
2367
|
+
pnpm add -D -w @changesets/cli
|
|
2368
|
+
```
|
|
2369
|
+
|
|
2370
|
+
**初始化**:
|
|
2371
|
+
|
|
2372
|
+
```bash
|
|
2373
|
+
pnpm changeset init
|
|
2374
|
+
```
|
|
2375
|
+
|
|
2376
|
+
**添加变更**:
|
|
2377
|
+
|
|
2378
|
+
```bash
|
|
2379
|
+
pnpm changeset
|
|
2380
|
+
```
|
|
2381
|
+
|
|
2382
|
+
**发布流程**:
|
|
2383
|
+
|
|
2384
|
+
创建 `.github/workflows/release.yml`:
|
|
2385
|
+
|
|
2386
|
+
```yaml
|
|
2387
|
+
name: Release
|
|
2388
|
+
|
|
2389
|
+
on:
|
|
2390
|
+
push:
|
|
2391
|
+
branches:
|
|
2392
|
+
- main
|
|
2393
|
+
|
|
2394
|
+
jobs:
|
|
2395
|
+
release:
|
|
2396
|
+
runs-on: ubuntu-latest
|
|
2397
|
+
steps:
|
|
2398
|
+
- uses: actions/checkout@v3
|
|
2399
|
+
with:
|
|
2400
|
+
fetch-depth: 0
|
|
2401
|
+
|
|
2402
|
+
- name: Setup pnpm
|
|
2403
|
+
uses: pnpm/action-setup@v2
|
|
2404
|
+
with:
|
|
2405
|
+
version: 8
|
|
2406
|
+
|
|
2407
|
+
- name: Setup Node.js
|
|
2408
|
+
uses: actions/setup-node@v3
|
|
2409
|
+
with:
|
|
2410
|
+
node-version: 18
|
|
2411
|
+
cache: 'pnpm'
|
|
2412
|
+
registry-url: 'https://registry.npmjs.org'
|
|
2413
|
+
|
|
2414
|
+
- name: Install dependencies
|
|
2415
|
+
run: pnpm install
|
|
2416
|
+
|
|
2417
|
+
- name: Build packages
|
|
2418
|
+
run: pnpm build
|
|
2419
|
+
|
|
2420
|
+
- name: Create Release Pull Request or Publish
|
|
2421
|
+
id: changesets
|
|
2422
|
+
uses: changesets/action@v1
|
|
2423
|
+
with:
|
|
2424
|
+
publish: pnpm changeset publish
|
|
2425
|
+
version: pnpm changeset version
|
|
2426
|
+
env:
|
|
2427
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
2428
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
2429
|
+
```
|
|
2430
|
+
|
|
2431
|
+
---
|
|
2432
|
+
|
|
2433
|
+
### 五、发布命令速查表
|
|
2434
|
+
|
|
2435
|
+
```bash
|
|
2436
|
+
# ========== 文档站点 ==========
|
|
2437
|
+
|
|
2438
|
+
# 构建文档
|
|
2439
|
+
pnpm build:docs
|
|
2440
|
+
|
|
2441
|
+
# 预览文档
|
|
2442
|
+
pnpm preview:docs
|
|
2443
|
+
|
|
2444
|
+
# ========== Packages 打包 ==========
|
|
2445
|
+
|
|
2446
|
+
# 构建所有包
|
|
2447
|
+
pnpm build
|
|
2448
|
+
|
|
2449
|
+
# 构建单个包
|
|
2450
|
+
pnpm --filter @m-design/components build
|
|
2451
|
+
pnpm --filter @m-design/icons build
|
|
2452
|
+
pnpm --filter @m-design/styles build
|
|
2453
|
+
pnpm --filter @m-design/utils build
|
|
2454
|
+
|
|
2455
|
+
# ========== npm 发布 ==========
|
|
2456
|
+
|
|
2457
|
+
# 登录 npm
|
|
2458
|
+
npm login
|
|
2459
|
+
|
|
2460
|
+
# 检查登录状态
|
|
2461
|
+
npm whoami
|
|
2462
|
+
|
|
2463
|
+
# 检查包名
|
|
2464
|
+
npm view @your-org/components
|
|
2465
|
+
|
|
2466
|
+
# 发布单个包
|
|
2467
|
+
cd packages/components && npm publish
|
|
2468
|
+
|
|
2469
|
+
# 更新版本号
|
|
2470
|
+
npm version patch # 修订号
|
|
2471
|
+
npm version minor # 次版本号
|
|
2472
|
+
npm version major # 主版本号
|
|
2473
|
+
|
|
2474
|
+
# 查看已发布的包
|
|
2475
|
+
npm view @your-org/components versions
|
|
2476
|
+
```
|
|
2477
|
+
|
|
2478
|
+
---
|
|
2479
|
+
|
|
2480
|
+
## 常见问题
|
|
2481
|
+
|
|
2482
|
+
### 1. Sass @import 弃用警告
|
|
2483
|
+
|
|
2484
|
+
**问题**:出现 `@import rules are deprecated` 警告
|
|
2485
|
+
|
|
2486
|
+
**解决**:使用 `@use` 替代 `@import`,但注意 `@use` 必须在所有其他规则之前。
|
|
2487
|
+
|
|
2488
|
+
### 2. TypeScript 找不到模块
|
|
2489
|
+
|
|
2490
|
+
**问题**:`找不到模块"@m-design/components"`
|
|
2491
|
+
|
|
2492
|
+
**解决**:确保在 `docs/tsconfig.json` 中配置了正确的路径别名。
|
|
2493
|
+
|
|
2494
|
+
### 3. VitePress 无法解析样式
|
|
2495
|
+
|
|
2496
|
+
**问题**:样式文件无法加载
|
|
2497
|
+
|
|
2498
|
+
**解决**:确保在 `docs/.vitepress/config.ts` 中配置了正确的 alias 和 CSS 预处理器选项。
|
|
2499
|
+
|
|
2500
|
+
### 4. Element Plus 样式未加载
|
|
2501
|
+
|
|
2502
|
+
**问题**:Element Plus 组件没有样式
|
|
2503
|
+
|
|
2504
|
+
**解决**:确保在使用的地方导入了 `element-plus/dist/index.css`,并且要在 `@m-design/styles` 之前导入。
|
|
2505
|
+
|
|
2506
|
+
---
|
|
2507
|
+
|
|
2508
|
+
## 下一步
|
|
2509
|
+
|
|
2510
|
+
1. 添加更多组件
|
|
2511
|
+
2. 完善文档
|
|
2512
|
+
3. 添加单元测试
|
|
2513
|
+
4. 配置 CI/CD
|
|
2514
|
+
5. 发布到 npm
|
|
2515
|
+
|
|
2516
|
+
---
|
|
2517
|
+
|
|
2518
|
+
## 总结
|
|
2519
|
+
|
|
2520
|
+
通过本指南,你已经成功创建了一个完整的 Monorepo 组件库项目,包括:
|
|
2521
|
+
|
|
2522
|
+
- ✅ Monorepo 架构配置
|
|
2523
|
+
- ✅ 组件包(Button、Table)
|
|
2524
|
+
- ✅ 图标包
|
|
2525
|
+
- ✅ 样式包(变量、混入、覆写、工具类)
|
|
2526
|
+
- ✅ 工具包(日期、格式化、验证、存储等)
|
|
2527
|
+
- ✅ VitePress 文档站点
|
|
2528
|
+
|
|
2529
|
+
现在你可以开始开发自己的组件库了!
|
|
2530
|
+
|