fix(vite): pass modulesDir to isExternal (#21966)

This commit is contained in:
Daniel Roe 2023-07-06 14:22:31 +01:00 committed by GitHub
parent d590c85c35
commit 1605a532a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View File

@ -229,7 +229,7 @@ export async function initViteDevBundler (ctx: ViteBuildContext, onBuild: () =>
const viteServer = ctx.ssrServer!
const options: TransformOptions = {
viteServer,
isExternal: createIsExternal(viteServer, ctx.nuxt.options.rootDir)
isExternal: createIsExternal(viteServer, ctx.nuxt.options.rootDir, ctx.nuxt.options.modulesDir)
}
// Build and watch

View File

@ -2,7 +2,7 @@ import type { ExternalsOptions } from 'externality'
import { ExternalsDefaults, isExternal } from 'externality'
import type { ViteDevServer } from 'vite'
export function createIsExternal (viteServer: ViteDevServer, rootDir: string) {
export function createIsExternal (viteServer: ViteDevServer, rootDir: string, modulesDirs?: string[]) {
const externalOpts: ExternalsOptions = {
inline: [
/virtual:/,
@ -15,6 +15,7 @@ export function createIsExternal (viteServer: ViteDevServer, rootDir: string) {
/node_modules/
],
resolve: {
modules: modulesDirs,
type: 'module',
extensions: ['.ts', '.js', '.json', '.vue', '.mjs', '.jsx', '.tsx', '.wasm']
}

View File

@ -128,7 +128,7 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
web: []
}
})
const isExternal = createIsExternal(viteServer, ctx.nuxt.options.rootDir)
const isExternal = createIsExternal(viteServer, ctx.nuxt.options.rootDir, ctx.nuxt.options.modulesDir)
node.shouldExternalize = async (id: string) => {
const result = await isExternal(id)
if (result?.external) {