diff --git a/packages/vite/src/dev-bundler.ts b/packages/vite/src/dev-bundler.ts index 7ec7b7a033..23a1d3370e 100644 --- a/packages/vite/src/dev-bundler.ts +++ b/packages/vite/src/dev-bundler.ts @@ -25,12 +25,19 @@ function isExternal (opts: TransformOptions, id: string) { // Externals const ssrConfig = (opts.viteServer.config as any).ssr + // Vite's alias have two possible formats + // https://vitejs.dev/config/#resolve-alias + const alias = opts.viteServer.config.resolve.alias || {} + const aliasKeys = Array.isArray(alias) + ? alias.map(i => i.find).filter(Boolean) + : Object.keys(alias) + const externalOpts: ExternalsOptions = { inline: [ /virtual:/, /\.ts$/, // Things like '~', '@', etc. - ...Object.keys(opts.viteServer.config.resolve.alias), + ...aliasKeys, ...ExternalsDefaults.inline, ...ssrConfig.noExternal ],