mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-20 16:25:55 +00:00
fix(nuxt): fully resolve nuxt dependencies (#31436)
This commit is contained in:
parent
efd4e2a50d
commit
26d0e18061
@ -5,6 +5,8 @@ import noOnlyTests from 'eslint-plugin-no-only-tests'
|
|||||||
import typegen from 'eslint-typegen'
|
import typegen from 'eslint-typegen'
|
||||||
import perfectionist from 'eslint-plugin-perfectionist'
|
import perfectionist from 'eslint-plugin-perfectionist'
|
||||||
|
|
||||||
|
import { runtimeDependencies } from './packages/nuxt/src/meta.mjs'
|
||||||
|
|
||||||
export default createConfigForNuxt({
|
export default createConfigForNuxt({
|
||||||
features: {
|
features: {
|
||||||
stylistic: {
|
stylistic: {
|
||||||
@ -188,23 +190,7 @@ export default createConfigForNuxt({
|
|||||||
'vue/server-renderer',
|
'vue/server-renderer',
|
||||||
'vue',
|
'vue',
|
||||||
'vue-router',
|
'vue-router',
|
||||||
// other deps
|
...runtimeDependencies,
|
||||||
'devalue',
|
|
||||||
'klona',
|
|
||||||
// unjs ecosystem
|
|
||||||
'defu',
|
|
||||||
'ufo',
|
|
||||||
'h3',
|
|
||||||
'destr',
|
|
||||||
'consola',
|
|
||||||
'hookable',
|
|
||||||
'unctx',
|
|
||||||
'cookie-es',
|
|
||||||
'perfect-debounce',
|
|
||||||
'radix3',
|
|
||||||
'ohash',
|
|
||||||
'pathe',
|
|
||||||
'uncrypto',
|
|
||||||
'errx', /* only used in dev */
|
'errx', /* only used in dev */
|
||||||
// internal deps
|
// internal deps
|
||||||
'nuxt/app',
|
'nuxt/app',
|
||||||
|
@ -2,6 +2,9 @@ import type { Plugin } from 'vite'
|
|||||||
import { tryImportModule } from '@nuxt/kit'
|
import { tryImportModule } from '@nuxt/kit'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import type { Nitro } from 'nitro/types'
|
import type { Nitro } from 'nitro/types'
|
||||||
|
import { resolveModulePath } from 'exsolve'
|
||||||
|
|
||||||
|
import { runtimeDependencies as runtimeNuxtDependencies } from '../../meta.mjs'
|
||||||
|
|
||||||
export function ResolveExternalsPlugin (nuxt: Nuxt): Plugin {
|
export function ResolveExternalsPlugin (nuxt: Nuxt): Plugin {
|
||||||
let external: Set<string> = new Set()
|
let external: Set<string> = new Set()
|
||||||
@ -11,17 +14,18 @@ export function ResolveExternalsPlugin (nuxt: Nuxt): Plugin {
|
|||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
async configResolved () {
|
async configResolved () {
|
||||||
if (!nuxt.options.dev) {
|
if (!nuxt.options.dev) {
|
||||||
const { runtimeDependencies = [] } = await tryImportModule<typeof import('nitro/runtime/meta')>('nitro/runtime/meta', {
|
const { runtimeDependencies: runtimeNitroDependencies = [] } = await tryImportModule<typeof import('nitro/runtime/meta')>('nitro/runtime/meta', {
|
||||||
url: new URL(import.meta.url),
|
url: new URL(import.meta.url),
|
||||||
}) || {}
|
}) || {}
|
||||||
|
|
||||||
external = new Set([
|
external = new Set([
|
||||||
// explicit dependencies we use in our ssr renderer - these can be inlined (if necessary) in the nitro build
|
// explicit dependencies we use in our ssr renderer - these can be inlined (if necessary) in the nitro build
|
||||||
'unhead', '@unhead/vue', 'unctx', 'h3', 'devalue', '@nuxt/devalue', 'radix3', 'rou3', 'unstorage', 'hookable',
|
'unhead', '@unhead/vue', '@nuxt/devalue', 'rou3', 'unstorage',
|
||||||
// ensure we only have one version of vue if nitro is going to inline anyway
|
// ensure we only have one version of vue if nitro is going to inline anyway
|
||||||
...((nuxt as any)._nitro as Nitro).options.inlineDynamicImports ? ['vue', '@vue/server-renderer', '@unhead/vue'] : [],
|
...((nuxt as any)._nitro as Nitro).options.inlineDynamicImports ? ['vue', '@vue/server-renderer'] : [],
|
||||||
|
...runtimeNuxtDependencies,
|
||||||
// dependencies we might share with nitro - these can be inlined (if necessary) in the nitro build
|
// dependencies we might share with nitro - these can be inlined (if necessary) in the nitro build
|
||||||
...runtimeDependencies,
|
...runtimeNitroDependencies,
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -32,6 +36,13 @@ export function ResolveExternalsPlugin (nuxt: Nuxt): Plugin {
|
|||||||
|
|
||||||
const res = await this.resolve?.(id, importer, { skipSelf: true })
|
const res = await this.resolve?.(id, importer, { skipSelf: true })
|
||||||
if (res !== undefined && res !== null) {
|
if (res !== undefined && res !== null) {
|
||||||
|
if (res.id === id) {
|
||||||
|
res.id = resolveModulePath(res.id, {
|
||||||
|
try: true,
|
||||||
|
from: importer,
|
||||||
|
extensions: nuxt.options.extensions,
|
||||||
|
}) || res.id
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...res,
|
...res,
|
||||||
external: 'absolute',
|
external: 'absolute',
|
||||||
|
19
packages/nuxt/src/meta.mjs
Normal file
19
packages/nuxt/src/meta.mjs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export const runtimeDependencies = [
|
||||||
|
// other deps
|
||||||
|
'devalue',
|
||||||
|
'klona',
|
||||||
|
// unjs ecosystem
|
||||||
|
'defu',
|
||||||
|
'ufo',
|
||||||
|
'h3',
|
||||||
|
'destr',
|
||||||
|
'consola',
|
||||||
|
'hookable',
|
||||||
|
'unctx',
|
||||||
|
'cookie-es',
|
||||||
|
'perfect-debounce',
|
||||||
|
'radix3',
|
||||||
|
'ohash',
|
||||||
|
'pathe',
|
||||||
|
'uncrypto',
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user