mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-22 11:22:43 +00:00
refactor(vite): drop externality
and use vite internal config (#30634)
This commit is contained in:
parent
c315eb9805
commit
7cfc338ed7
@ -6,14 +6,12 @@ import { isAbsolute, normalize, resolve } from 'pathe'
|
|||||||
// import { addDevServerHandler } from '@nuxt/kit'
|
// import { addDevServerHandler } from '@nuxt/kit'
|
||||||
import { isFileServingAllowed } from 'vite'
|
import { isFileServingAllowed } from 'vite'
|
||||||
import type { ModuleNode, Plugin as VitePlugin } from 'vite'
|
import type { ModuleNode, Plugin as VitePlugin } from 'vite'
|
||||||
import { getQuery } from 'ufo'
|
import { getQuery, withTrailingSlash } from 'ufo'
|
||||||
import { normalizeViteManifest } from 'vue-bundle-renderer'
|
import { normalizeViteManifest } from 'vue-bundle-renderer'
|
||||||
import { resolve as resolveModule } from 'mlly'
|
import escapeStringRegexp from 'escape-string-regexp'
|
||||||
import { distDir } from './dirs'
|
import { distDir } from './dirs'
|
||||||
import type { ViteBuildContext } from './vite'
|
import type { ViteBuildContext } from './vite'
|
||||||
import { isCSS } from './utils'
|
import { isCSS } from './utils'
|
||||||
import { createIsExternal } from './utils/external'
|
|
||||||
import { transpile } from './utils/transpile'
|
|
||||||
|
|
||||||
// TODO: Remove this in favor of registerViteNodeMiddleware
|
// TODO: Remove this in favor of registerViteNodeMiddleware
|
||||||
// after Nitropack or h3 allows adding middleware after setup
|
// after Nitropack or h3 allows adding middleware after setup
|
||||||
@ -118,9 +116,13 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
|||||||
const node = new ViteNodeServer(viteServer, {
|
const node = new ViteNodeServer(viteServer, {
|
||||||
deps: {
|
deps: {
|
||||||
inline: [
|
inline: [
|
||||||
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
// Common
|
||||||
/^#/,
|
/^#/,
|
||||||
...transpile({ isServer: true, isDev: ctx.nuxt.options.dev }),
|
/\?/,
|
||||||
|
],
|
||||||
|
external: [
|
||||||
|
'#shared',
|
||||||
|
new RegExp('^' + escapeStringRegexp(withTrailingSlash(resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)))),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
transformMode: {
|
transformMode: {
|
||||||
@ -129,15 +131,6 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const isExternal = createIsExternal(viteServer, ctx.nuxt)
|
|
||||||
node.shouldExternalize = async (id: string) => {
|
|
||||||
const result = await isExternal(id)
|
|
||||||
if (result?.external) {
|
|
||||||
return resolveModule(result.id, { url: ctx.nuxt.options.modulesDir }).catch(() => false)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return eventHandler(async (event) => {
|
return eventHandler(async (event) => {
|
||||||
const moduleId = decodeURI(event.path).substring(1)
|
const moduleId = decodeURI(event.path).substring(1)
|
||||||
if (moduleId === '/') {
|
if (moduleId === '/') {
|
||||||
|
Loading…
Reference in New Issue
Block a user