mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 00:23:53 +00:00
fix(kit,vite,webpack): resolve postcss paths from each modules dir (#29096)
This commit is contained in:
parent
70a622d433
commit
9d77fdc802
@ -85,7 +85,6 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
||||
|
||||
// Import if input is string
|
||||
if (typeof nuxtModule === 'string') {
|
||||
let error: unknown
|
||||
const paths = [join(nuxtModule, 'nuxt'), join(nuxtModule, 'module'), nuxtModule, join(nuxt.options.rootDir, nuxtModule)]
|
||||
|
||||
for (const parentURL of nuxt.options.modulesDir) {
|
||||
@ -100,16 +99,17 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
||||
buildTimeModuleMeta = JSON.parse(await fsp.readFile(moduleMetadataPath, 'utf-8'))
|
||||
}
|
||||
break
|
||||
} catch (_err: unknown) {
|
||||
error = _err
|
||||
} catch (error: unknown) {
|
||||
const code = (error as Error & { code?: string }).code
|
||||
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_MODULE_NOT_FOUND' || code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
|
||||
continue
|
||||
}
|
||||
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
if (typeof nuxtModule !== 'string') { break }
|
||||
}
|
||||
if (typeof nuxtModule !== 'function' && error) {
|
||||
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Throw error if input is not a function
|
||||
|
@ -27,11 +27,16 @@ export async function resolveCSSOptions (nuxt: Nuxt): Promise<ViteConfig['css']>
|
||||
const pluginOptions = postcssOptions.plugins[pluginName]
|
||||
if (!pluginOptions) { continue }
|
||||
|
||||
const path = jiti.esmResolve(pluginName)
|
||||
const pluginFn = (await jiti.import(path)) as (opts: Record<string, any>) => Plugin
|
||||
if (typeof pluginFn === 'function') {
|
||||
css.postcss.plugins.push(pluginFn(pluginOptions))
|
||||
} else {
|
||||
let pluginFn: ((opts: Record<string, any>) => Plugin) | undefined
|
||||
for (const parentURL of nuxt.options.modulesDir) {
|
||||
pluginFn = await jiti.import(pluginName, { parentURL, try: true }) as (opts: Record<string, any>) => Plugin
|
||||
if (typeof pluginFn === 'function') {
|
||||
css.postcss.plugins.push(pluginFn(pluginOptions))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof pluginFn !== 'function') {
|
||||
console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`)
|
||||
}
|
||||
}
|
||||
|
@ -49,11 +49,16 @@ export async function getPostcssConfig (nuxt: Nuxt) {
|
||||
const pluginOptions = postcssOptions.plugins[pluginName]
|
||||
if (!pluginOptions) { continue }
|
||||
|
||||
const path = jiti.esmResolve(pluginName)
|
||||
const pluginFn = (await jiti.import(path)) as (opts: Record<string, any>) => Plugin
|
||||
if (typeof pluginFn === 'function') {
|
||||
plugins.push(pluginFn(pluginOptions))
|
||||
} else {
|
||||
let pluginFn: ((opts: Record<string, any>) => Plugin) | undefined
|
||||
for (const parentURL of nuxt.options.modulesDir) {
|
||||
pluginFn = await jiti.import(pluginName, { parentURL, try: true }) as (opts: Record<string, any>) => Plugin
|
||||
if (typeof pluginFn === 'function') {
|
||||
plugins.push(pluginFn(pluginOptions))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof pluginFn !== 'function') {
|
||||
console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user