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 }) => {