Skip to content

Commit

Permalink
fix: do not externalize monorepo modules, revert #9140
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 3, 2022
1 parent 0b89dd2 commit 7832eff
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions packages/vite/src/node/config.ts
Expand Up @@ -967,40 +967,12 @@ async function bundleConfigFile(
{
name: 'externalize-deps',
setup(build) {
build.onResolve({ filter: /.*/ }, ({ path: id, importer }) => {
// externalize bare imports
build.onResolve({ filter: /.*/ }, ({ path: id }) => {
if (id[0] !== '.' && !path.isAbsolute(id)) {
return {
external: true
}
}
// bundle the rest and make sure that the we can also access
// it's third-party dependencies. externalize if not.
// monorepo/
// ├─ package.json
// ├─ utils.js -----------> bundle (share same node_modules)
// ├─ vite-project/
// │ ├─ vite.config.js --> entry
// │ ├─ package.json
// ├─ foo-project/
// │ ├─ utils.js --------> external (has own node_modules)
// │ ├─ package.json
const idFsPath = path.resolve(path.dirname(importer), id)
const idPkgPath = lookupFile(idFsPath, [`package.json`], {
pathOnly: true
})
if (idPkgPath) {
const idPkgDir = path.dirname(idPkgPath)
// if this file needs to go up one or more directory to reach the vite config,
// that means it has it's own node_modules (e.g. foo-project)
if (path.relative(idPkgDir, fileName).startsWith('..')) {
return {
// normalize actual import after bundled as a single vite config
path: isESM ? pathToFileURL(idFsPath).href : idFsPath,
external: true
}
}
}
})
}
},
Expand Down

0 comments on commit 7832eff

Please sign in to comment.