@@ -901,14 +901,14 @@ async function bundleConfigFile(
901
901
name : 'externalize-deps' ,
902
902
setup ( build ) {
903
903
build . onResolve ( { filter : / .* / } , ( { path : id , importer } ) => {
904
- // bundle all relative paths
904
+ // externalize bare imports
905
905
if ( id [ 0 ] !== '.' && ! path . isAbsolute ( id ) ) {
906
906
return {
907
907
external : true
908
908
}
909
909
}
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.
912
912
// monorepo/
913
913
// ├─ package.json
914
914
// ├─ utils.js -----------> bundle (share same node_modules)
@@ -918,21 +918,19 @@ async function bundleConfigFile(
918
918
// ├─ foo-project/
919
919
// │ ├─ utils.js --------> external (has own node_modules)
920
920
// │ ├─ 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
936
934
}
937
935
}
938
936
}
0 commit comments