@@ -21,6 +21,7 @@ import type {
21
21
Format ,
22
22
LibConfig ,
23
23
PkgJson ,
24
+ RsbuildConfigOutputTarget ,
24
25
RslibConfig ,
25
26
RslibConfigAsyncFn ,
26
27
RslibConfigExport ,
@@ -39,7 +40,10 @@ import {
39
40
readPackageJson ,
40
41
} from './utils/helper' ;
41
42
import { logger } from './utils/logger' ;
42
- import { transformSyntaxToBrowserslist } from './utils/syntax' ;
43
+ import {
44
+ ESX_TO_BROWSERSLIST ,
45
+ transformSyntaxToBrowserslist ,
46
+ } from './utils/syntax' ;
43
47
import { loadTsconfig } from './utils/tsconfig' ;
44
48
45
49
/**
@@ -551,7 +555,7 @@ const composeAutoExtensionConfig = (
551
555
552
556
const composeSyntaxConfig = (
553
557
syntax ?: Syntax ,
554
- target ?: string ,
558
+ target ?: RsbuildConfigOutputTarget ,
555
559
) : RsbuildConfig => {
556
560
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
557
561
@@ -567,24 +571,11 @@ const composeSyntaxConfig = (
567
571
} ,
568
572
} ,
569
573
output : {
570
- overrideBrowserslist : transformSyntaxToBrowserslist ( syntax ) ,
574
+ overrideBrowserslist : transformSyntaxToBrowserslist ( syntax , target ) ,
571
575
} ,
572
576
} ;
573
577
}
574
578
575
- // If `syntax` is not defined, Rslib will try to determine by the `target`, with the last version of the target.
576
- const lastTargetVersions = {
577
- node : [ 'last 1 node versions' ] ,
578
- web : [
579
- 'last 1 Chrome versions' ,
580
- 'last 1 Firefox versions' ,
581
- 'last 1 Edge versions' ,
582
- 'last 1 Safari versions' ,
583
- 'last 1 ios_saf versions' ,
584
- 'not dead' ,
585
- ] ,
586
- } ;
587
-
588
579
return {
589
580
tools : {
590
581
rspack : ( config ) => {
@@ -593,12 +584,8 @@ const composeSyntaxConfig = (
593
584
} ,
594
585
} ,
595
586
output : {
596
- overrideBrowserslist :
597
- target === 'web'
598
- ? lastTargetVersions . web
599
- : target === 'node'
600
- ? lastTargetVersions . node
601
- : [ ...lastTargetVersions . node , ...lastTargetVersions . web ] ,
587
+ // If `syntax` is not defined, Rslib will try to determine by the `target`, with the last version of the target.
588
+ overrideBrowserslist : ESX_TO_BROWSERSLIST . esnext ( target ) ,
602
589
} ,
603
590
} ;
604
591
} ;
@@ -695,6 +682,7 @@ const composeBundleConfig = (
695
682
? request . replace ( / \. [ ^ . ] + $ / , jsExtension )
696
683
: `${ request } ${ jsExtension } ` ;
697
684
}
685
+
698
686
return callback ( null , request ) ;
699
687
}
700
688
callback ( ) ;
@@ -728,7 +716,9 @@ const composeDtsConfig = async (
728
716
} ;
729
717
} ;
730
718
731
- const composeTargetConfig = ( target = 'web' ) : RsbuildConfig => {
719
+ const composeTargetConfig = (
720
+ target : RsbuildConfigOutputTarget = 'web' ,
721
+ ) : RsbuildConfig => {
732
722
switch ( target ) {
733
723
case 'web' :
734
724
return {
@@ -756,14 +746,15 @@ const composeTargetConfig = (target = 'web'): RsbuildConfig => {
756
746
target : 'node' ,
757
747
} ,
758
748
} ;
759
- case 'neutral' :
760
- return {
761
- tools : {
762
- rspack : {
763
- target : [ 'web' , 'node' ] ,
764
- } ,
765
- } ,
766
- } ;
749
+ // TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field.
750
+ // case 'neutral':
751
+ // return {
752
+ // tools: {
753
+ // rspack: {
754
+ // target: ['web', 'node'],
755
+ // },
756
+ // },
757
+ // };
767
758
default :
768
759
throw new Error ( `Unsupported platform: ${ target } ` ) ;
769
760
}
0 commit comments