Skip to content

Commit

Permalink
Merge pull request #67 from xuanhen2013/main
Browse files Browse the repository at this point in the history
  • Loading branch information
aibayanyu20 authored Oct 23, 2024
2 parents 1ffc2b7 + 66b2d7a commit 2a727a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
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';

0 comments on commit 2a727a8

Please sign in to comment.