From b3b388d424ac7ca33fa5e6ae0c3aaf9cccb17ec0 Mon Sep 17 00:00:00 2001 From: ysy945 <79794654+ysy945@users.noreply.github.com> Date: Fri, 14 Oct 2022 17:33:27 +0800 Subject: [PATCH] refactor: delete dependent pre built proxy modules (#10427) --- .../src/node/optimizer/esbuildDepPlugin.ts | 47 +------------------ 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 66b0bcdbe050a9..c90ea58ec73b42 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] } } } @@ -179,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 @@ -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 }) => {