From cac70e469629e86385b614de3eab4436c184e3d7 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 23 Dec 2021 21:43:41 +0800 Subject: [PATCH] fix(vite): remove vite's query for external modules (#2521) --- packages/vite/src/dev-bundler.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/dev-bundler.ts b/packages/vite/src/dev-bundler.ts index 753291af44..0c006b01ae 100644 --- a/packages/vite/src/dev-bundler.ts +++ b/packages/vite/src/dev-bundler.ts @@ -3,6 +3,7 @@ import { existsSync } from 'fs' import { resolve } from 'pathe' import * as vite from 'vite' import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality' +import { parseURL } from 'ufo' import { hashId, uniq } from './utils' export interface TransformChunk { @@ -69,9 +70,11 @@ async function transformRequest (opts: TransformOptions, id: string) { } } - if (await isExternal(opts, id)) { + const { pathname } = parseURL(id) + + if (await isExternal(opts, pathname)) { return { - code: `(global, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) => import('${(pathToFileURL(id))}').then(r => { exports.default = r.default; ssrExportAll(r) }).catch(e => { console.error(e); throw new Error('[vite dev] Error loading external "${id}".') })`, + code: `(global, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) => import('${(pathToFileURL(pathname))}').then(r => { exports.default = r.default; ssrExportAll(r) }).catch(e => { console.error(e); throw new Error('[vite dev] Error loading external "${id}".') })`, deps: [], dynamicDeps: [] }