diff --git a/src/core/components.ts b/src/core/components.ts index 4be0454..fd93d19 100644 --- a/src/core/components.ts +++ b/src/core/components.ts @@ -1,11 +1,10 @@ -import { addComponent, createResolver } from '@nuxt/kit' +import { addComponent } from '@nuxt/kit' import { libraryName } from '../config' -import { hyphenate, toArray } from '../utils' +import { hyphenate, resolvePath, toArray } from '../utils' import type { ModuleOptions } from '../types' export function resolveComponents (config: ModuleOptions) { const { components, excludeExports } = config - const { resolvePath } = createResolver(import.meta.url) components.forEach(async (item) => { const [name, alias, from] = toArray(item) diff --git a/src/core/transformPlugin.ts b/src/core/transformPlugin.ts index 79fd8eb..b51dc6d 100644 --- a/src/core/transformPlugin.ts +++ b/src/core/transformPlugin.ts @@ -1,9 +1,8 @@ import { createUnplugin } from 'unplugin' import MagicString from 'magic-string' import type { NuxtOptions } from '@nuxt/schema' -import { createResolver } from '@nuxt/kit' import { allImportsWithStyle, libraryName } from '../config' -import { camelize, genSideEffectsImport, toRegExp } from '../utils' +import { camelize, genSideEffectsImport, resolvePath, toRegExp } from '../utils' import type { TransformOptions } from '../types' interface PluginOptions extends TransformOptions { @@ -34,7 +33,6 @@ export const transformPlugin = createUnplugin((options: PluginOptions) => { } }, async transform (code, id) { - const { resolvePath } = createResolver(import.meta.url) const styles = new Set() const s = new MagicString(code) diff --git a/src/utils.ts b/src/utils.ts index 0e8caba..093cf0d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,12 @@ +import { createResolver } from '@nuxt/kit' import type { NuxtConfigLayer } from '@nuxt/schema' import { libraryName } from './config' +export function resolvePath (path: string): Promise { + const { resolvePath } = createResolver(import.meta.url) + return resolvePath(path) +} + export function getLayersDir (layers: NuxtConfigLayer[]) { const list = []