Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: delete dependent pre built proxy modules #10427

Merged
merged 4 commits into from Oct 14, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 2 additions & 45 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
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