Skip to content

Commit

Permalink
feat(projects): 添加全局组件自动引入注册
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 12, 2022
1 parent 094dca9 commit f5a043b
Show file tree
Hide file tree
Showing 32 changed files with 77 additions and 35 deletions.
21 changes: 21 additions & 0 deletions build/plugins/auto-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
import Components from 'unplugin-vue-components/vite';
import { FileSystemIconLoader } from 'unplugin-icons/loaders';

export default (srcPath: string) => {
return [
Icons({
compiler: 'vue3',
customCollections: {
custom: FileSystemIconLoader(`${srcPath}/assets/svg`),
},
scale: 1,
defaultClass: 'inline-block',
}),
Components({
dts: true,
resolvers: [IconsResolver({ customCollections: ['custom'], componentPrefix: 'icon' })],
}),
];
};
2 changes: 1 addition & 1 deletion build/plugins/iconify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default (srcPath: string) => {
defaultClass: 'inline-block',
}),
Components({
dts: false,
dts: true,
resolvers: [IconsResolver({ customCollections: ['custom'], componentPrefix: 'icon' })],
}),
];
Expand Down
4 changes: 2 additions & 2 deletions build/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ConfigEnv, PluginOption } from 'vite';
import vue from './vue';
import html from './html';
import iconify from './iconify';
import autoImport from './auto-import';
import windicss from './windicss';
import mock from './mock';
import visualizer from './visualizer';
Expand All @@ -17,7 +17,7 @@ export function setupVitePlugins(
srcPath: string,
viteEnv: ImportMetaEnv
): (PluginOption | PluginOption[])[] {
const plugins = [vue, html(configEnv), ...iconify(srcPath), windicss, mock];
const plugins = [vue, html(configEnv), ...autoImport(srcPath), windicss, mock];

if (configEnv.command === 'build' && viteEnv.VITE_VISUALIZER === 'true') {
plugins.push(visualizer);
Expand Down
48 changes: 48 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/vue-next/pull/3399

declare module 'vue' {
export interface GlobalComponents {
BetterScroll: typeof import('./src/components/custom/BetterScroll.vue')['default'];
CountTo: typeof import('./src/components/custom/CountTo.vue')['default'];
DarkModeContainer: typeof import('./src/components/common/DarkModeContainer.vue')['default'];
DarkModeSwitch: typeof import('./src/components/common/DarkModeSwitch.vue')['default'];
GithubLink: typeof import('./src/components/custom/GithubLink.vue')['default'];
HoverContainer: typeof import('./src/components/common/HoverContainer.vue')['default'];
IconAntDesignCloseOutlined: typeof import('~icons/ant-design/close-outlined')['default'];
IconAntDesignEnterOutlined: typeof import('~icons/ant-design/enter-outlined')['default'];
IconAntDesignSettingOutlined: typeof import('~icons/ant-design/setting-outlined')['default'];
IconCustomAvatar: typeof import('~icons/custom/avatar')['default'];
IconCustomEmptyData: typeof import('~icons/custom/empty-data')['default'];
IconCustomLogo: typeof import('~icons/custom/logo')['default'];
IconCustomLogoFill: typeof import('~icons/custom/logo-fill')['default'];
IconCustomNetworkError: typeof import('~icons/custom/network-error')['default'];
IconGridiconsFullscreen: typeof import('~icons/gridicons/fullscreen')['default'];
IconGridiconsFullscreenExit: typeof import('~icons/gridicons/fullscreen-exit')['default'];
IconIcOutlineCheck: typeof import('~icons/ic/outline-check')['default'];
IconLineMdMenuFoldLeft: typeof import('~icons/line-md/menu-fold-left')['default'];
IconLineMdMenuUnfoldLeft: typeof import('~icons/line-md/menu-unfold-left')['default'];
IconMdiArrowDownThin: typeof import('~icons/mdi/arrow-down-thin')['default'];
IconMdiArrowUpThin: typeof import('~icons/mdi/arrow-up-thin')['default'];
IconMdiClose: typeof import('~icons/mdi/close')['default'];
IconMdiGithub: typeof import('~icons/mdi/github')['default'];
IconMdiMoonWaningCrescent: typeof import('~icons/mdi/moon-waning-crescent')['default'];
IconMdiPin: typeof import('~icons/mdi/pin')['default'];
IconMdiPinOff: typeof import('~icons/mdi/pin-off')['default'];
IconMdiRefresh: typeof import('~icons/mdi/refresh')['default'];
IconMdiWhiteBalanceSunny: typeof import('~icons/mdi/white-balance-sunny')['default'];
IconPhCaretDoubleLeftBold: typeof import('~icons/ph/caret-double-left-bold')['default'];
IconPhCaretDoubleRightBold: typeof import('~icons/ph/caret-double-right-bold')['default'];
IconSelect: typeof import('./src/components/custom/IconSelect.vue')['default'];
IconUilSearch: typeof import('~icons/uil/search')['default'];
ImageVerify: typeof import('./src/components/custom/ImageVerify.vue')['default'];
LoadingEmptyWrapper: typeof import('./src/components/business/LoadingEmptyWrapper.vue')['default'];
LoginAgreement: typeof import('./src/components/business/LoginAgreement.vue')['default'];
NaiveProvider: typeof import('./src/components/common/NaiveProvider.vue')['default'];
SystemLogo: typeof import('./src/components/common/SystemLogo.vue')['default'];
WebSiteLink: typeof import('./src/components/custom/WebSiteLink.vue')['default'];
}
}

export {};
1 change: 0 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<script setup lang="ts">
import { zhCN, dateZhCN } from 'naive-ui';
import { NaiveProvider } from '@/components';
import { useThemeStore, subscribeStore } from '@/store';
const theme = useThemeStore();
Expand Down
4 changes: 1 addition & 3 deletions src/layouts/common/GlobalFooter/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
</dark-mode-container>
</template>

<script setup lang="ts">
import { DarkModeContainer } from '@/components';
</script>
<script setup lang="ts"></script>
<style scoped></style>
1 change: 0 additions & 1 deletion src/layouts/common/GlobalHeader/components/FullScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<script lang="ts" setup>
import { useFullscreen } from '@vueuse/core';
import { HoverContainer } from '@/components';
const { isFullscreen, toggle } = useFullscreen();
</script>
Expand Down
4 changes: 1 addition & 3 deletions src/layouts/common/GlobalHeader/components/GithubSite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
</hover-container>
</template>

<script lang="ts" setup>
import { HoverContainer } from '@/components';
</script>
<script lang="ts" setup></script>
<style scoped></style>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</template>

<script lang="ts" setup>
import { HoverContainer } from '@/components';
import { useAppStore } from '@/store';
const app = useAppStore();
Expand Down
1 change: 0 additions & 1 deletion src/layouts/common/GlobalHeader/components/ThemeMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</template>

<script lang="ts" setup>
import { HoverContainer, DarkModeSwitch } from '@/components';
import { useThemeStore } from '@/store';
const theme = useThemeStore();
Expand Down
1 change: 0 additions & 1 deletion src/layouts/common/GlobalHeader/components/UserAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</template>

<script lang="ts" setup>
import { HoverContainer } from '@/components';
import { useAuthStore } from '@/store';
import { iconifyRender } from '@/utils';
Expand Down
1 change: 0 additions & 1 deletion src/layouts/common/GlobalHeader/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</template>

<script setup lang="ts">
import { DarkModeContainer } from '@/components';
import { useThemeStore } from '@/store';
import GlobalLogo from '../GlobalLogo/index.vue';
import GlobalSearch from '../GlobalSearch/index.vue';
Expand Down
1 change: 0 additions & 1 deletion src/layouts/common/GlobalLogo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</template>

<script setup lang="ts">
import { SystemLogo } from '@/components';
import { routePath } from '@/router';
import { useAppInfo } from '@/composables';
Expand Down
1 change: 0 additions & 1 deletion src/layouts/common/GlobalSearch/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</template>

<script lang="ts" setup>
import { HoverContainer } from '@/components';
import { useBoolean } from '@/hooks';
import { SearchModal } from './components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import { ref, computed, watch } from 'vue';
import { useRoute } from 'vue-router';
import type { MenuOption } from 'naive-ui';
import { DarkModeContainer } from '@/components';
import { useAppStore, useThemeStore } from '@/store';
import { useAppInfo, useRouterPush } from '@/composables';
import { getActiveKeyPathsOfMenus } from '@/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { DarkModeContainer } from '@/components';
import { useAppStore, useThemeStore, useRouteStore } from '@/store';
import { useRouterPush } from '@/composables';
import { useBoolean } from '@/hooks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<script setup lang="ts">
import { computed } from 'vue';
import { DarkModeContainer } from '@/components';
import { useAppStore, useThemeStore } from '@/store';
import { GlobalLogo } from '@/layouts/common';
import { VerticalMenu } from './components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</template>

<script setup lang="ts">
import { HoverContainer } from '@/components';
import { useAppStore } from '@/store';
import { useLoading } from '@/hooks';
Expand Down
1 change: 0 additions & 1 deletion src/layouts/common/GlobalTab/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useElementBounding } from '@vueuse/core';
import { DarkModeContainer, BetterScroll } from '@/components';
import { useThemeStore, useTabStore } from '@/store';
import { useDeviceInfo } from '@/composables';
import { TabDetail, ReloadButton } from './components';
Expand Down
1 change: 0 additions & 1 deletion src/views/component/table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import type { DataTableColumn } from 'naive-ui';
import { LoadingEmptyWrapper } from '@/components';
import { useLoadingEmpty } from '@/hooks';
import { getRandomInterger } from '@/utils';
Expand Down
1 change: 0 additions & 1 deletion src/views/dashboard/analysis/components/DataCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<script setup lang="ts">
import { Icon } from '@iconify/vue';
import { CountTo } from '@/components';
import { GradientBg } from './components';
interface CardData {
Expand Down
1 change: 0 additions & 1 deletion src/views/dashboard/analysis/components/TopChart/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { Line, Pie } from '@antv/g2plot';
import { CountTo } from '@/components';
import data from './data.json';
const lineRef = ref<HTMLElement>();
Expand Down
1 change: 0 additions & 1 deletion src/views/plugin/editor/markdown/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import { ref, watch, onMounted, onUnmounted } from 'vue';
import Vditor from 'vditor';
import 'vditor/src/assets/scss/index.scss';
import { GithubLink } from '@/components';
import { useThemeStore } from '@/store';
const theme = useThemeStore();
Expand Down
1 change: 0 additions & 1 deletion src/views/plugin/editor/quill/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import WangEditor from 'wangeditor';
import { GithubLink } from '@/components';
const editor = ref<WangEditor>();
const domRef = ref<HTMLElement>();
Expand Down
1 change: 0 additions & 1 deletion src/views/plugin/icon/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { Icon } from '@iconify/vue';
import { IconSelect, WebSiteLink } from '@/components';
import { icons } from './icons';
const selectValue = ref('');
Expand Down
1 change: 0 additions & 1 deletion src/views/plugin/print/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<script lang="ts" setup>
import printJS from 'print-js';
import { GithubLink } from '@/components';
function printTable() {
printJS({
Expand Down
1 change: 0 additions & 1 deletion src/views/plugin/swiper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import SwiperCore, { Navigation, Pagination } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import type { SwiperOptions } from 'swiper';
import { WebSiteLink, GithubLink } from '@/components';
type SwiperExampleOptions = Pick<
SwiperOptions,
Expand Down
1 change: 0 additions & 1 deletion src/views/system-view/login/components/CodeLogin/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<script setup lang="ts">
import { reactive, ref } from 'vue';
import type { FormInst } from 'naive-ui';
import { ImageVerify } from '@/components';
import { useAuthStore } from '@/store';
import { useRouterPush } from '@/composables';
import { useSmsCode } from '@/hooks';
Expand Down
1 change: 0 additions & 1 deletion src/views/system-view/login/components/Register/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue';
import type { FormInst, FormRules } from 'naive-ui';
import { LoginAgreement } from '@/components';
import { useRouterPush } from '@/composables';
import { useSmsCode } from '@/hooks';
import { formRules, getConfirmPwdRule } from '@/utils';
Expand Down
1 change: 0 additions & 1 deletion src/views/system-view/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import { computed } from 'vue';
import type { Component } from 'vue';
import { EnumLoginModule } from '@/enum';
import { SystemLogo, DarkModeSwitch } from '@/components';
import { useThemeStore } from '@/store';
import { useAppInfo } from '@/composables';
import { getColorPalette, mixColor } from '@/utils';
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"mock/**/*.ts",
"build/**/*.ts",
".env-config.ts",
"components.d.ts"
],
"exclude": [
"/dist/**",
Expand All @@ -19,6 +20,6 @@
"@/*": ["./src/*"],
"~/*": ["./*"]
},
"types": ["node","naive-ui/volar"]
"types": ["node","unplugin-icons/types/vue","naive-ui/volar"]
}
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig((configEnv) => {
resolve: {
alias: {
'@': srcPath,
'~': rootPath,
'~/': rootPath,
},
},
define,
Expand Down

0 comments on commit f5a043b

Please sign in to comment.