From 16d0833efd461c95932b2c41a473e66ea7e2efa7 Mon Sep 17 00:00:00 2001 From: yangxingyuan Date: Fri, 5 Nov 2021 21:54:22 +0800 Subject: [PATCH 1/2] fix: sourcemap error with plugin-react --- packages/plugin-react/src/index.ts | 9 +++++++++ pnpm-lock.yaml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 2cc9eaab5a5f75..f94737b620eee5 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -52,6 +52,9 @@ export default function viteReact(opts: Options = {}): PluginOption[] { let skipFastRefresh = opts.fastRefresh === false let skipReactImport = false + // The dir where pre-bundled deps is stored + let cacheDir: string + const useAutomaticRuntime = opts.jsxRuntime !== 'classic' const userPlugins = opts.babel?.plugins || [] @@ -78,6 +81,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { }) isProduction = config.isProduction skipFastRefresh ||= isProduction || config.command === 'build' + cacheDir = config.cacheDir as string const jsxInject = config.esbuild && config.esbuild.jsxInject if (jsxInject && importReactRE.test(jsxInject)) { @@ -107,6 +111,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] { filepath.match(fileExtensionRE) || [] + // Pre-bundle deps should not be transformed there. #5438 + if (id.startsWith(cacheDir)) { + return + } + if (/\.(mjs|[tj]sx?)$/.test(extension)) { const plugins = [...userPlugins] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e86f24fd601903..f69fe06b35edf0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7183,7 +7183,7 @@ packages: dev: true /pvutils/1.0.17: - resolution: {integrity: sha512-wLHYUQxWaXVQvKnwIDWFVKDJku9XDCvyhhxoq8dc5MFdIlRenyPI9eSfEtcvgHgD7FlvCyGAlWgOzRnZD99GZQ==} + resolution: {integrity: sha1-rePHTf5xeJRP5EgGYmvS4knZlr8=} engines: {node: '>=6.0.0'} dev: true From e68944687762d5078f8dfd984c8530035944be6e Mon Sep 17 00:00:00 2001 From: "494130947@qq.com" <494130947@qq.com> Date: Sat, 6 Nov 2021 11:11:36 +0800 Subject: [PATCH 2/2] fix: include sourcesContent after remapping --- packages/vite/src/node/utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 4d6d4436b4248b..2f87a0bbb55af4 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -520,7 +520,8 @@ export function combineSourcemaps( const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === undefined if (useArrayInterface) { - map = remapping(sourcemapList, () => null, true) + // We cann't exclude sourcesContent there. #5438 + map = remapping(sourcemapList, () => null, false) } else { map = remapping( sourcemapList[0], @@ -531,7 +532,7 @@ export function combineSourcemaps( return { ...nullSourceMap } } }, - true + false ) } if (!map.file) {