@@ -889,13 +889,14 @@ const composeEntryConfig = async (
889
889
bundle : LibConfig [ 'bundle' ] ,
890
890
root : string ,
891
891
cssModulesAuto : CssLoaderOptionsAuto ,
892
- ) : Promise < { entryConfig : EnvironmentConfig ; lcp : string | null } > => {
892
+ userOutBase ?: string ,
893
+ ) : Promise < { entryConfig : EnvironmentConfig ; outBase : string | null } > => {
893
894
let entries : RsbuildConfigEntry = rawEntry ;
894
895
895
896
if ( ! entries ) {
896
897
// In bundle mode, return directly to let Rsbuild apply default entry to './src/index.ts'
897
898
if ( bundle !== false ) {
898
- return { entryConfig : { } , lcp : null } ;
899
+ return { entryConfig : { } , outBase : null } ;
899
900
}
900
901
901
902
// In bundleless mode, set default entry to './src/**'
@@ -957,13 +958,22 @@ const composeEntryConfig = async (
957
958
entry : appendEntryQuery ( resolveEntryPath ( entries , root ) ) ,
958
959
} ,
959
960
} ,
960
- lcp : null ,
961
+ outBase : null ,
961
962
} ;
962
963
}
963
964
964
- const scanGlobEntries = async ( calcLcp : boolean ) => {
965
+ const scanGlobEntries = async ( tryResolveOutBase : boolean ) => {
965
966
// In bundleless mode, resolve glob patterns and convert them to entry object.
966
967
const resolvedEntries : Record < string , string > = { } ;
968
+
969
+ const resolveOutBase = async ( resolvedEntryFiles : string [ ] ) => {
970
+ // Similar to `rootDir` in tsconfig and `outbase` in esbuild.
971
+ const lcp = await calcLongestCommonPath ( resolvedEntryFiles ) ;
972
+ // Using the longest common path of all non-declaration input files by default.
973
+ const outBase = userOutBase ?? ( lcp === null ? root : lcp ) ;
974
+ return outBase ;
975
+ } ;
976
+
967
977
for ( const key of Object . keys ( entries ) ) {
968
978
const entry = entries [ key ] ;
969
979
@@ -998,10 +1008,7 @@ const composeEntryConfig = async (
998
1008
throw new Error ( `Cannot find ${ resolvedEntryFiles } ` ) ;
999
1009
}
1000
1010
1001
- // Similar to `rootDir` in tsconfig and `outbase` in esbuild.
1002
- const lcp = await calcLongestCommonPath ( resolvedEntryFiles ) ;
1003
- // Using the longest common path of all non-declaration input files by default.
1004
- const outBase = lcp === null ? root : lcp ;
1011
+ const outBase = await resolveOutBase ( resolvedEntryFiles ) ;
1005
1012
1006
1013
function getEntryName ( file : string ) {
1007
1014
const { dir, name } = path . parse ( path . relative ( outBase , file ) ) ;
@@ -1021,7 +1028,7 @@ const composeEntryConfig = async (
1021
1028
const entryName = getEntryName ( file ) ;
1022
1029
1023
1030
if ( resolvedEntries [ entryName ] ) {
1024
- calcLcp &&
1031
+ tryResolveOutBase &&
1025
1032
logger . warn (
1026
1033
`Duplicate entry ${ color . cyan ( entryName ) } from ${ color . cyan (
1027
1034
path . relative ( root , file ) ,
@@ -1035,15 +1042,15 @@ const composeEntryConfig = async (
1035
1042
}
1036
1043
}
1037
1044
1038
- if ( calcLcp ) {
1039
- const lcp = await calcLongestCommonPath ( Object . values ( resolvedEntries ) ) ;
1040
- return { resolvedEntries, lcp } ;
1045
+ if ( tryResolveOutBase ) {
1046
+ const outBase = await resolveOutBase ( Object . values ( resolvedEntries ) ) ;
1047
+ return { resolvedEntries, outBase } ;
1041
1048
}
1042
- return { resolvedEntries, lcp : null } ;
1049
+ return { resolvedEntries, outBase : null } ;
1043
1050
} ;
1044
1051
1045
- // LCP could only be determined at the first time of glob scan.
1046
- const { lcp } = await scanGlobEntries ( true ) ;
1052
+ // OutBase could only be determined at the first time of glob scan.
1053
+ const { outBase } = await scanGlobEntries ( true ) ;
1047
1054
const entryConfig : EnvironmentConfig = {
1048
1055
tools : {
1049
1056
rspack : {
@@ -1057,7 +1064,7 @@ const composeEntryConfig = async (
1057
1064
1058
1065
return {
1059
1066
entryConfig,
1060
- lcp ,
1067
+ outBase ,
1061
1068
} ;
1062
1069
} ;
1063
1070
@@ -1415,14 +1422,15 @@ async function composeLibRsbuildConfig(
1415
1422
pkgJson,
1416
1423
userExternals : config . output ?. externals ,
1417
1424
} ) ;
1418
- const { entryConfig, lcp } = await composeEntryConfig (
1425
+ const { entryConfig, outBase } = await composeEntryConfig (
1419
1426
config . source ?. entry ! ,
1420
1427
config . bundle ,
1421
1428
rootPath ,
1422
1429
cssModulesAuto ,
1430
+ config . outBase ,
1423
1431
) ;
1424
1432
const cssConfig = composeCssConfig (
1425
- lcp ,
1433
+ outBase ,
1426
1434
config . bundle ,
1427
1435
banner ?. css ,
1428
1436
footer ?. css ,
@@ -1431,7 +1439,7 @@ async function composeLibRsbuildConfig(
1431
1439
1432
1440
const entryChunkConfig = composeEntryChunkConfig ( {
1433
1441
enabledImportMetaUrlShim : enabledShims . cjs [ 'import.meta.url' ] ,
1434
- contextToWatch : lcp ,
1442
+ contextToWatch : outBase ,
1435
1443
} ) ;
1436
1444
const dtsConfig = await composeDtsConfig ( config , dtsExtension ) ;
1437
1445
const externalsWarnConfig = composeExternalsWarnConfig (
@@ -1548,6 +1556,7 @@ export async function composeCreateRsbuildConfig(
1548
1556
dts : true ,
1549
1557
shims : true ,
1550
1558
umdName : true ,
1559
+ outBase : true ,
1551
1560
} ) ,
1552
1561
) ,
1553
1562
} ;
0 commit comments