Skip to content

Commit

Permalink
refactor: delete dependent pre built proxy modules (#10427)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysy945 authored Oct 14, 2022
1 parent 8116cbd commit b3b388d
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ export function esbuildDepPlugin(
const flatId = flattenId(id)
if (flatId in qualified) {
return {
path: flatId,
namespace: 'dep'
path: qualified[flatId]
}
}
}
Expand All @@ -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
Expand All @@ -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 }) => {
Expand Down

0 comments on commit b3b388d

Please sign in to comment.