Skip to content

Commit d613c6a

Browse files
committed
fix: should resolve esnext browserslist
1 parent 63bb9ed commit d613c6a

File tree

4 files changed

+218
-159
lines changed

4 files changed

+218
-159
lines changed

packages/core/src/config.ts

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
Format,
2222
LibConfig,
2323
PkgJson,
24+
RsbuildConfigOutputTarget,
2425
RslibConfig,
2526
RslibConfigAsyncFn,
2627
RslibConfigExport,
@@ -39,7 +40,10 @@ import {
3940
readPackageJson,
4041
} from './utils/helper';
4142
import { logger } from './utils/logger';
42-
import { transformSyntaxToBrowserslist } from './utils/syntax';
43+
import {
44+
ESX_TO_BROWSERSLIST,
45+
transformSyntaxToBrowserslist,
46+
} from './utils/syntax';
4347
import { loadTsconfig } from './utils/tsconfig';
4448

4549
/**
@@ -551,7 +555,7 @@ const composeAutoExtensionConfig = (
551555

552556
const composeSyntaxConfig = (
553557
syntax?: Syntax,
554-
target?: string,
558+
target?: RsbuildConfigOutputTarget,
555559
): RsbuildConfig => {
556560
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
557561

@@ -567,24 +571,11 @@ const composeSyntaxConfig = (
567571
},
568572
},
569573
output: {
570-
overrideBrowserslist: transformSyntaxToBrowserslist(syntax),
574+
overrideBrowserslist: transformSyntaxToBrowserslist(syntax, target),
571575
},
572576
};
573577
}
574578

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-
588579
return {
589580
tools: {
590581
rspack: (config) => {
@@ -593,12 +584,8 @@ const composeSyntaxConfig = (
593584
},
594585
},
595586
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),
602589
},
603590
};
604591
};
@@ -695,6 +682,7 @@ const composeBundleConfig = (
695682
? request.replace(/\.[^.]+$/, jsExtension)
696683
: `${request}${jsExtension}`;
697684
}
685+
698686
return callback(null, request);
699687
}
700688
callback();
@@ -728,7 +716,9 @@ const composeDtsConfig = async (
728716
};
729717
};
730718

731-
const composeTargetConfig = (target = 'web'): RsbuildConfig => {
719+
const composeTargetConfig = (
720+
target: RsbuildConfigOutputTarget = 'web',
721+
): RsbuildConfig => {
732722
switch (target) {
733723
case 'web':
734724
return {
@@ -756,14 +746,15 @@ const composeTargetConfig = (target = 'web'): RsbuildConfig => {
756746
target: 'node',
757747
},
758748
};
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+
// };
767758
default:
768759
throw new Error(`Unsupported platform: ${target}`);
769760
}

packages/core/src/types/config/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import type { RsbuildConfig } from '@rsbuild/core';
22

33
export type Format = 'esm' | 'cjs' | 'umd';
44

5-
export type EcmaScriptVersion =
6-
| 'esnext'
5+
export type FixedEcmaVersions =
76
| 'es5'
87
| 'es6'
98
| 'es2015'
@@ -14,8 +13,13 @@ export type EcmaScriptVersion =
1413
| 'es2020'
1514
| 'es2021'
1615
| 'es2022'
17-
| 'es2023'
18-
| 'es2024';
16+
| 'es2023';
17+
export type LatestEcmaVersions = 'es2024' | 'esnext';
18+
export type EcmaScriptVersion = FixedEcmaVersions | LatestEcmaVersions;
19+
20+
export type RsbuildConfigOutputTarget = NonNullable<
21+
RsbuildConfig['output']
22+
>['target'];
1923

2024
export type Syntax =
2125
// ECMAScript versions as an common used addition to browserslist query

0 commit comments

Comments
 (0)