Skip to content

fix: 修复本地开发将所有组件拆包方式加载 #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/core/components.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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=>{
if (typeof component === 'string'){
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
})
}
})
Expand All @@ -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
})
}
})
Expand Down
5 changes: 2 additions & 3 deletions src/core/imports.ts
Original file line number Diff line number Diff line change
@@ -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]
})
}
6 changes: 5 additions & 1 deletion src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export default defineNuxtModule<Partial<Options>>({
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()
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/antd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from 'ant-design-vue/es';
export * from '@ant-design/icons-vue';