From 66b2d7aba9e0e64251e018cf4711d7446a24538b Mon Sep 17 00:00:00 2001 From: xuanhen2013 <1072671832@qq.com> Date: Fri, 18 Oct 2024 10:34:32 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=B0=86=E6=89=80=E6=9C=89=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=8B=86=E5=8C=85=E6=96=B9=E5=BC=8F=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/components.ts | 13 +++++++------ src/core/imports.ts | 5 ++--- src/core/options.ts | 6 +++++- src/module.ts | 7 +++++-- src/runtime/antd.ts | 2 ++ 5 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 src/runtime/antd.ts diff --git a/src/core/components.ts b/src/core/components.ts index 51aa945..946bfc5 100644 --- a/src/core/components.ts +++ b/src/core/components.ts @@ -1,8 +1,9 @@ import type { Options } from "../types"; -import { iconLibraryName, libraryName, prefix } from "../config" +import { prefix } from "../config" import { addComponent } from "@nuxt/kit"; -export const resolveComponents = (config:Options) =>{ +export const resolveComponents = (config:Options, filePath: string) =>{ + const { components,icons } = config; const allComponents = components === false ? [] : components; allComponents.forEach(component=>{ @@ -10,13 +11,13 @@ export const resolveComponents = (config:Options) =>{ addComponent({ export: component, name: prefix + component, - filePath: libraryName + '/es' + filePath }) }else if (Array.isArray(component)){ addComponent({ export: component[0], name: prefix + component[1], - filePath: libraryName + '/es' + filePath }) } }) @@ -29,13 +30,13 @@ export const resolveComponents = (config:Options) =>{ addComponent({ export: icon, name: icon, - filePath: iconLibraryName + filePath }) }else if (Array.isArray(icon)){ addComponent({ export: icon[0], name: icon[1], - filePath: iconLibraryName + filePath }) } }) diff --git a/src/core/imports.ts b/src/core/imports.ts index 75e9a72..5dadc38 100644 --- a/src/core/imports.ts +++ b/src/core/imports.ts @@ -1,12 +1,11 @@ import { addImportsSources } from "@nuxt/kit"; import type { Options } from "../types"; -import { libraryName } from "../config"; -export const resolveImports = (config:Options) => { +export const resolveImports = (config:Options, filePath: string) => { const { imports } = config const allImports = imports ? imports : [] addImportsSources({ - from: libraryName + '/es', + from: filePath, imports: [...allImports] }) } diff --git a/src/core/options.ts b/src/core/options.ts index 0d4d0ba..ea348be 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -16,9 +16,13 @@ export function resolveOptions () { resolve:{ alias:[ { - find: /^(ant-design-vue)(?!\/(es|dist))/, + find: /^(ant-design-vue)(?!\/(es|lib))/, replacement: 'ant-design-vue/es', }, + { + find: /^@ant-design\/icons-vue$/, + replacement: '@ant-design/icons-vue', + }, { find: /^dayjs\/plugin\/(.*)$/, replacement: 'dayjs/esm/plugin/$1', diff --git a/src/module.ts b/src/module.ts index 3908725..d8a85e2 100644 --- a/src/module.ts +++ b/src/module.ts @@ -15,10 +15,13 @@ export default defineNuxtModule>({ const options = _options as Options; resolveOptions() + + const antdRuntimePath = createResolver(import.meta.url).resolve('./runtime/antd') + // eslint-disable-next-line @typescript-eslint/no-unused-expressions - nuxt.options.imports.autoImport !== false && resolveImports(options) + nuxt.options.imports.autoImport !== false && resolveImports(options, antdRuntimePath) // eslint-disable-next-line @typescript-eslint/no-unused-expressions - nuxt.options.components !== false && resolveComponents(options) + nuxt.options.components !== false && resolveComponents(options, antdRuntimePath) if (options.extractStyle) { extractStyle() diff --git a/src/runtime/antd.ts b/src/runtime/antd.ts new file mode 100644 index 0000000..4ede6bd --- /dev/null +++ b/src/runtime/antd.ts @@ -0,0 +1,2 @@ +export * from 'ant-design-vue/es'; +export * from '@ant-design/icons-vue';