Skip to content

Commit

Permalink
fix(optimizer): browser-external proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
swandir committed Jan 27, 2022
1 parent 1dce5eb commit 76a49da
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Expand Up @@ -34,6 +34,21 @@ const externalTypes = [
...KNOWN_ASSET_TYPES
]

const browserExternalContents = (id: string) => `\
module.exports = new Proxy({}, {
get() {
return new Proxy({}, {
get() {
throw new Error(
'Module "${id}" has been externalized for ' +
'browser compatibility and cannot be accessed in client code.'
)
}
})
}
})
`

export function esbuildDepPlugin(
qualified: Record<string, string>,
exportsData: Record<string, ExportsData>,
Expand Down Expand Up @@ -197,15 +212,7 @@ export function esbuildDepPlugin(
build.onLoad(
{ filter: /.*/, namespace: 'browser-external' },
({ path: id }) => {
return {
contents:
`export default new Proxy({}, {
get() {
throw new Error('Module "${id}" has been externalized for ` +
`browser compatibility and cannot be accessed in client code.')
}
})`
}
return { contents: browserExternalContents(id) }
}
)

Expand Down

0 comments on commit 76a49da

Please sign in to comment.