From 4e92ad76473e5c24d71da6d578035851a26e30e1 Mon Sep 17 00:00:00 2001 From: ysy945 <79794654+ysy945@users.noreply.github.com> Date: Tue, 11 Oct 2022 18:23:15 +0800 Subject: [PATCH 1/4] Delete dependent pre built virtual modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the old version of "esbuild", in order to flatten the dependent pre built products, the agent module will be used to process the "require ('react /jsx runtime. js')". The reason why the path was not directly modified to redirect to the entry is that the products will have a nested structure. The subsequent wrapper is also added to prevent secondary packaging. However, for the current version of "esbuild", even if it is directly redirected to the entry module, the product name is still specified by "entryPoints" and will not result in secondary packaging or nested products. Therefore, we do not need to use the proxy module now. After deleting and adding the above code, “vite” still runs well, and the pre built product and product size will not change. --- .../src/node/optimizer/esbuildDepPlugin.ts | 45 +------------------ 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 66b0bcdbe050a9..91e9e205fef231 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -162,8 +162,7 @@ export function esbuildDepPlugin( const flatId = flattenId(id) if (flatId in qualified) { return { - path: flatId, - namespace: 'dep' + path: qualified[flatId], } } } @@ -198,48 +197,6 @@ export function esbuildDepPlugin( } ) - // For entry files, we'll read it ourselves and construct a proxy module - // to retain the entry's raw id instead of file path so that esbuild - // outputs desired output file structure. - // It is necessary to do the re-exporting to separate the virtual proxy - // module from the actual module since the actual module may get - // referenced via relative imports - if we don't separate the proxy and - // the actual module, esbuild will create duplicated copies of the same - // module! - const root = path.resolve(config.root) - build.onLoad({ filter: /.*/, namespace: 'dep' }, ({ path: id }) => { - const entryFile = qualified[id] - - let relativePath = normalizePath(path.relative(root, entryFile)) - if ( - !relativePath.startsWith('./') && - !relativePath.startsWith('../') && - relativePath !== '.' - ) { - relativePath = `./${relativePath}` - } - - let contents = '' - const { hasImports, exports, hasReExports } = exportsData[id] - if (!hasImports && !exports.length) { - // cjs - contents += `export default require("${relativePath}");` - } else { - if (exports.includes('default')) { - contents += `import d from "${relativePath}";export default d;` - } - if (hasReExports || exports.length > 1 || exports[0] !== 'default') { - contents += `\nexport * from "${relativePath}"` - } - } - - return { - loader: 'js', - contents, - resolveDir: root - } - }) - build.onLoad( { filter: /.*/, namespace: 'browser-external' }, ({ path }) => { From 7428e4c86758a1f144219f4bbb6306213e22d7ae Mon Sep 17 00:00:00 2001 From: ysy945 <79794654+ysy945@users.noreply.github.com> Date: Tue, 11 Oct 2022 19:16:47 +0800 Subject: [PATCH 2/4] update update the error of typescript --- packages/vite/src/node/optimizer/esbuildDepPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 91e9e205fef231..9c4f2487112347 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -178,7 +178,7 @@ export function esbuildDepPlugin( } // ensure esbuild uses our resolved entries - let entry: { path: string; namespace: string } | undefined + let entry: { path: string} | undefined // if this is an entry, return entry namespace resolve result if (!importer) { if ((entry = resolveEntry(id))) return entry From 8a7f5e929298f448e06dac45d5a9d0e7ef1bfebe Mon Sep 17 00:00:00 2001 From: ysy945 <79794654+ysy945@users.noreply.github.com> Date: Tue, 11 Oct 2022 19:33:41 +0800 Subject: [PATCH 3/4] Update esbuildDepPlugin.ts --- packages/vite/src/node/optimizer/esbuildDepPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 9c4f2487112347..1c7f3a5fefe032 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -178,7 +178,7 @@ export function esbuildDepPlugin( } // ensure esbuild uses our resolved entries - let entry: { path: string} | undefined + let entry: { path: string } | undefined // if this is an entry, return entry namespace resolve result if (!importer) { if ((entry = resolveEntry(id))) return entry From 126be37e77ddae19843c97f2cadb00aa2a892b8b Mon Sep 17 00:00:00 2001 From: ysy945 <79794654+ysy945@users.noreply.github.com> Date: Fri, 14 Oct 2022 12:32:40 +0800 Subject: [PATCH 4/4] none --- packages/vite/src/node/optimizer/esbuildDepPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 1c7f3a5fefe032..c90ea58ec73b42 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -162,7 +162,7 @@ export function esbuildDepPlugin( const flatId = flattenId(id) if (flatId in qualified) { return { - path: qualified[flatId], + path: qualified[flatId] } } }