Skip to content

Commit

Permalink
fix: check for all other imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 15, 2022
1 parent 0bd053d commit 763a568
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,14 @@ async function bundleConfigFile(
name: 'externalize-deps',
setup(build) {
build.onResolve({ filter: /.*/ }, ({ path: id, importer }) => {
// bundle all relative paths
// externalize bare imports
if (id[0] !== '.' && !path.isAbsolute(id)) {
return {
external: true
}
}
// if the file is outside of a vite project, make sure that the we can
// also access it's third-party dependencies. externalize if not.
// 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)
Expand All @@ -918,21 +918,19 @@ async function bundleConfigFile(
// ├─ foo-project/
// │ ├─ utils.js --------> external (has own node_modules)
// │ ├─ package.json
if (id.startsWith('..')) {
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 relative import after bundled as a single vite config
path: path.relative(path.dirname(fileName), idFsPath),
external: true
}
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: idFsPath,
external: true
}
}
}
Expand Down

0 comments on commit 763a568

Please sign in to comment.