Skip to content

Commit 763a568

Browse files
committed
fix: check for all other imports
1 parent 0bd053d commit 763a568

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

packages/vite/src/node/config.ts

+16-18
Original file line numberDiff line numberDiff line change
@@ -901,14 +901,14 @@ async function bundleConfigFile(
901901
name: 'externalize-deps',
902902
setup(build) {
903903
build.onResolve({ filter: /.*/ }, ({ path: id, importer }) => {
904-
// bundle all relative paths
904+
// externalize bare imports
905905
if (id[0] !== '.' && !path.isAbsolute(id)) {
906906
return {
907907
external: true
908908
}
909909
}
910-
// if the file is outside of a vite project, make sure that the we can
911-
// also access it's third-party dependencies. externalize if not.
910+
// bundle the rest and make sure that the we can also access
911+
// it's third-party dependencies. externalize if not.
912912
// monorepo/
913913
// ├─ package.json
914914
// ├─ utils.js -----------> bundle (share same node_modules)
@@ -918,21 +918,19 @@ async function bundleConfigFile(
918918
// ├─ foo-project/
919919
// │ ├─ utils.js --------> external (has own node_modules)
920920
// │ ├─ package.json
921-
if (id.startsWith('..')) {
922-
const idFsPath = path.resolve(path.dirname(importer), id)
923-
const idPkgPath = lookupFile(idFsPath, [`package.json`], {
924-
pathOnly: true
925-
})
926-
if (idPkgPath) {
927-
const idPkgDir = path.dirname(idPkgPath)
928-
// if this file needs to go up one or more directory to reach the vite config,
929-
// that means it has it's own node_modules (e.g. foo-project)
930-
if (path.relative(idPkgDir, fileName).startsWith('..')) {
931-
return {
932-
// normalize actual relative import after bundled as a single vite config
933-
path: path.relative(path.dirname(fileName), idFsPath),
934-
external: true
935-
}
921+
const idFsPath = path.resolve(path.dirname(importer), id)
922+
const idPkgPath = lookupFile(idFsPath, [`package.json`], {
923+
pathOnly: true
924+
})
925+
if (idPkgPath) {
926+
const idPkgDir = path.dirname(idPkgPath)
927+
// if this file needs to go up one or more directory to reach the vite config,
928+
// that means it has it's own node_modules (e.g. foo-project)
929+
if (path.relative(idPkgDir, fileName).startsWith('..')) {
930+
return {
931+
// normalize actual import after bundled as a single vite config
932+
path: idFsPath,
933+
external: true
936934
}
937935
}
938936
}

0 commit comments

Comments
 (0)