Skip to content

Commit

Permalink
feat: auto import naive
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jul 31, 2024
1 parent 4ea651b commit 34740a3
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 101 deletions.
2 changes: 1 addition & 1 deletion plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './_404Page';
export * from './commit';
export * from './mirror';
export * from './unAutoImport';
14 changes: 8 additions & 6 deletions plugins/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export const mirror = (): Plugin => {
apply: 'build',
enforce: 'post',
config() {
return {
experimental: {
renderBuiltUrl(filename) {
return mirrorBaseUrl + '/' + filename;
if (process.env.MIRROR == `ON`) {
return {
experimental: {
renderBuiltUrl(filename) {
return mirrorBaseUrl + '/' + filename;
},
},
},
};
};
}
},
};
};
152 changes: 152 additions & 0 deletions plugins/naive-components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[
"NA",
"NAffix",
"NAlert",
"NAnchor",
"NAnchorLink",
"NAutoComplete",
"NAvatar",
"NAvatarGroup",
"NBackTop",
"NBadge",
"NBlockquote",
"NBreadcrumb",
"NBreadcrumbItem",
"NButton",
"NButtonGroup",
"NCalendar",
"NCard",
"NCarousel",
"NCarouselItem",
"NCascader",
"NCheckbox",
"NCheckboxGroup",
"NCode",
"NCol",
"NCollapse",
"NCollapseItem",
"NCollapseTransition",
"NColorPicker",
"NConfigProvider",
"NCountdown",
"NDataTable",
"NDatePicker",
"NDescriptions",
"NDescriptionsItem",
"NDialog",
"NDialogProvider",
"NDivider",
"NDrawer",
"NDrawerContent",
"NDropdown",
"NDynamicInput",
"NDynamicTags",
"NEl",
"NElement",
"NEllipsis",
"NEmpty",
"NEquation",
"NFlex",
"NFloatButton",
"NFloatButtonGroup",
"NForm",
"NFormItem",
"NFormItemCol",
"NFormItemGi",
"NFormItemGridItem",
"NFormItemRow",
"NGi",
"NGlobalStyle",
"NGradientText",
"NGrid",
"NGridItem",
"NH1",
"NH2",
"NH3",
"NH4",
"NH5",
"NH6",
"NHr",
"NIcon",
"NIconWrapper",
"NImage",
"NImageGroup",
"NInfiniteScroll",
"NInput",
"NInputGroup",
"NInputGroupLabel",
"NInputNumber",
"NLayout",
"NLayoutContent",
"NLayoutFooter",
"NLayoutHeader",
"NLayoutSider",
"NLegacyTransfer",
"NLi",
"NList",
"NListItem",
"NLoadingBarProvider",
"NLog",
"NMention",
"NMenu",
"NMessageProvider",
"NModal",
"NModalProvider",
"NNotificationProvider",
"NNumberAnimation",
"NOl",
"NP",
"NPageHeader",
"NPagination",
"NPerformantEllipsis",
"NPopconfirm",
"NPopover",
"NPopselect",
"NProgress",
"NQrCode",
"NRadio",
"NRadioButton",
"NRadioGroup",
"NRate",
"NResult",
"NRow",
"NScrollbar",
"NSelect",
"NSkeleton",
"NSlider",
"NSpace",
"NSpin",
"NSplit",
"NStatistic",
"NStep",
"NSteps",
"NSwitch",
"NTab",
"NTabPane",
"NTable",
"NTabs",
"NTag",
"NTbody",
"NTd",
"NText",
"NTh",
"NThead",
"NThemeEditor",
"NThing",
"NTime",
"NTimePicker",
"NTimeline",
"NTimelineItem",
"NTooltip",
"NTr",
"NTransfer",
"NTree",
"NTreeSelect",
"NUl",
"NUpload",
"NUploadDragger",
"NUploadFileList",
"NUploadTrigger",
"NVirtualList",
"NWatermark"
]
38 changes: 38 additions & 0 deletions plugins/unAutoImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import autoImport from 'unplugin-auto-import/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import components from 'unplugin-vue-components/vite';
import type { Plugin } from 'vite';
import naiveComponents from './naive-components.json';

export const unAutoImport = (): Plugin[] => {
return [
autoImport({
dts: 'auto-import.d.ts',
imports: [
'vue',
'vue-router',
'@vueuse/core',
{
'naive-ui': [
'useDialog',
'useMessage',
'useNotification',
'useLoadingBar',
...naiveComponents,
],
},
],
eslintrc: {
enabled: true,
globalsPropValue: 'readonly',
filepath: '.eslintrc-auto-import.json',
},
dirs: [],
}),
components({
dts: 'auto-import-components.d.ts',
resolvers: [NaiveUiResolver()],
dirs: [],
}),
];
};
37 changes: 16 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { NConfigProvider, dateZhCN, zhCN } from 'naive-ui';
import { dateZhCN, zhCN } from 'naive-ui';
import { RouterView } from 'vue-router';
import ErrorDlg from './components/ErrorDlg.vue';
</script>
Expand Down
1 change: 0 additions & 1 deletion src/components/ActionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { useTask } from '@/utils/task';
import type { Snapshot } from '@/utils/types';
import { getImportUrl, githubUrlToSelfUrl } from '@/utils/url';
import { NButton, NIcon, NPopconfirm, NPopover, NSpace } from 'naive-ui';
const props = withDefaults(
defineProps<{
Expand Down
2 changes: 0 additions & 2 deletions src/components/ErrorDlg.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script setup lang="ts">
import { settingsStorage } from '@/utils/storage';
import store from '@/utils/store';
import { NModal, NCheckbox } from 'naive-ui';
</script>
<template>
<NModal
Expand Down
Loading

0 comments on commit 34740a3

Please sign in to comment.