mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
refactor(vite): drop externality
and use vite internal config
This commit is contained in:
parent
4d1d9fb3eb
commit
de8864a1d3
@ -41,7 +41,6 @@
|
|||||||
"defu": "^6.1.4",
|
"defu": "^6.1.4",
|
||||||
"esbuild": "^0.24.2",
|
"esbuild": "^0.24.2",
|
||||||
"escape-string-regexp": "^5.0.0",
|
"escape-string-regexp": "^5.0.0",
|
||||||
"externality": "^1.0.2",
|
|
||||||
"get-port-please": "^3.1.2",
|
"get-port-please": "^3.1.2",
|
||||||
"h3": "^1.13.1",
|
"h3": "^1.13.1",
|
||||||
"jiti": "^2.4.2",
|
"jiti": "^2.4.2",
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
import type { ExternalsOptions } from 'externality'
|
|
||||||
import { ExternalsDefaults, isExternal } from 'externality'
|
|
||||||
import type { ViteDevServer } from 'vite'
|
|
||||||
import escapeStringRegexp from 'escape-string-regexp'
|
|
||||||
import { withTrailingSlash } from 'ufo'
|
|
||||||
import type { Nuxt } from 'nuxt/schema'
|
|
||||||
import { resolve } from 'pathe'
|
|
||||||
import { toArray } from '.'
|
|
||||||
|
|
||||||
export function createIsExternal (viteServer: ViteDevServer, nuxt: Nuxt) {
|
|
||||||
const externalOpts: ExternalsOptions = {
|
|
||||||
inline: [
|
|
||||||
/virtual:/,
|
|
||||||
/\.ts$/,
|
|
||||||
...ExternalsDefaults.inline || [],
|
|
||||||
...(
|
|
||||||
viteServer.config.ssr.noExternal && viteServer.config.ssr.noExternal !== true
|
|
||||||
? toArray(viteServer.config.ssr.noExternal)
|
|
||||||
: []
|
|
||||||
),
|
|
||||||
],
|
|
||||||
external: [
|
|
||||||
'#shared',
|
|
||||||
new RegExp('^' + escapeStringRegexp(withTrailingSlash(resolve(nuxt.options.rootDir, nuxt.options.dir.shared)))),
|
|
||||||
...(viteServer.config.ssr.external as string[]) || [],
|
|
||||||
/node_modules/,
|
|
||||||
],
|
|
||||||
resolve: {
|
|
||||||
modules: nuxt.options.modulesDir,
|
|
||||||
type: 'module',
|
|
||||||
extensions: ['.ts', '.js', '.json', '.vue', '.mjs', '.jsx', '.tsx', '.wasm'],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return (id: string) => isExternal(id, nuxt.options.rootDir, externalOpts)
|
|
||||||
}
|
|
@ -6,13 +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, toArray } from './utils'
|
||||||
import { createIsExternal } from './utils/external'
|
|
||||||
import { transpile } from './utils/transpile'
|
import { transpile } from './utils/transpile'
|
||||||
|
|
||||||
// TODO: Remove this in favor of registerViteNodeMiddleware
|
// TODO: Remove this in favor of registerViteNodeMiddleware
|
||||||
@ -118,10 +117,27 @@ 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)\//,
|
/^virtual:/,
|
||||||
|
/\.ts$/,
|
||||||
|
// Rollup
|
||||||
|
/\0/,
|
||||||
|
// Common
|
||||||
/^#/,
|
/^#/,
|
||||||
|
/\?/,
|
||||||
|
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
||||||
|
...(
|
||||||
|
viteServer.config.ssr.noExternal && viteServer.config.ssr.noExternal !== true
|
||||||
|
? toArray(viteServer.config.ssr.noExternal)
|
||||||
|
: []
|
||||||
|
),
|
||||||
...transpile({ isServer: true, isDev: ctx.nuxt.options.dev }),
|
...transpile({ isServer: true, isDev: ctx.nuxt.options.dev }),
|
||||||
],
|
],
|
||||||
|
external: [
|
||||||
|
'#shared',
|
||||||
|
new RegExp('^' + escapeStringRegexp(withTrailingSlash(resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)))),
|
||||||
|
...(viteServer.config.ssr.external as string[]) || [],
|
||||||
|
/node_modules/,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
transformMode: {
|
transformMode: {
|
||||||
ssr: [/.*/],
|
ssr: [/.*/],
|
||||||
@ -129,15 +145,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 === '/') {
|
||||||
|
@ -843,9 +843,6 @@ importers:
|
|||||||
escape-string-regexp:
|
escape-string-regexp:
|
||||||
specifier: ^5.0.0
|
specifier: ^5.0.0
|
||||||
version: 5.0.0
|
version: 5.0.0
|
||||||
externality:
|
|
||||||
specifier: ^1.0.2
|
|
||||||
version: 1.0.2
|
|
||||||
get-port-please:
|
get-port-please:
|
||||||
specifier: ^3.1.2
|
specifier: ^3.1.2
|
||||||
version: 3.1.2
|
version: 3.1.2
|
||||||
@ -4455,9 +4452,6 @@ packages:
|
|||||||
extend@3.0.2:
|
extend@3.0.2:
|
||||||
resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==}
|
resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==}
|
||||||
|
|
||||||
externality@1.0.2:
|
|
||||||
resolution: {integrity: sha512-LyExtJWKxtgVzmgtEHyQtLFpw1KFhQphF9nTG8TpAIVkiI/xQ3FJh75tRFLYl4hkn7BNIIdLJInuDAavX35pMw==}
|
|
||||||
|
|
||||||
fake-indexeddb@6.0.0:
|
fake-indexeddb@6.0.0:
|
||||||
resolution: {integrity: sha512-YEboHE5VfopUclOck7LncgIqskAqnv4q0EWbYCaxKKjAvO93c+TJIaBuGy8CBFdbg9nKdpN3AuPRwVBJ4k7NrQ==}
|
resolution: {integrity: sha512-YEboHE5VfopUclOck7LncgIqskAqnv4q0EWbYCaxKKjAvO93c+TJIaBuGy8CBFdbg9nKdpN3AuPRwVBJ4k7NrQ==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
@ -12082,13 +12076,6 @@ snapshots:
|
|||||||
|
|
||||||
extend@3.0.2: {}
|
extend@3.0.2: {}
|
||||||
|
|
||||||
externality@1.0.2:
|
|
||||||
dependencies:
|
|
||||||
enhanced-resolve: 5.18.0
|
|
||||||
mlly: 1.7.4
|
|
||||||
pathe: 1.1.2
|
|
||||||
ufo: 1.5.4
|
|
||||||
|
|
||||||
fake-indexeddb@6.0.0: {}
|
fake-indexeddb@6.0.0: {}
|
||||||
|
|
||||||
fast-deep-equal@3.1.3: {}
|
fast-deep-equal@3.1.3: {}
|
||||||
|
Loading…
Reference in New Issue
Block a user