Skip to content

Commit 057cd87

Browse files
authored
fix: derive rspack.target from libConfig.syntax (#213)
1 parent ed9fe5b commit 057cd87

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

e2e/cases/syntax/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ test('should downgrade class private method with output.syntax config', async ()
2323
expect(entries.esm1).toContain('#bar');
2424

2525
expect(entries.cjs0).toContain('#bar');
26+
expect(entries.cjs0).toContain('()=>{'); // test webpack runtime arrow function
2627
expect(entries.cjs1).not.toContain('#bar');
28+
expect(entries.cjs1).not.toContain('()=>{'); // test webpack runtime arrow function
2729
});

packages/core/src/config.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,17 @@ const composeSyntaxConfig = (
560560
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
561561

562562
if (syntax) {
563+
const resolvedBrowserslist = transformSyntaxToBrowserslist(syntax, target);
563564
return {
564565
tools: {
565566
rspack: (config) => {
566-
// TODO: Rspack should could resolve `browserslist:{query}` like webpack.
567-
// https://webpack.js.org/configuration/target/#browserslist
568-
// Using 'es5' as a temporary solution for compatibility.
569-
config.target = ['es5'];
570-
return config;
567+
config.target = resolvedBrowserslist.map(
568+
(item) => `browserslist:${item}` as const,
569+
);
571570
},
572571
},
573572
output: {
574-
overrideBrowserslist: transformSyntaxToBrowserslist(syntax, target),
573+
overrideBrowserslist: resolvedBrowserslist,
575574
},
576575
};
577576
}
@@ -725,6 +724,11 @@ const composeTargetConfig = (
725724
tools: {
726725
rspack: {
727726
target: ['web'],
727+
output: {
728+
chunkLoading: 'import',
729+
workerChunkLoading: 'import',
730+
wasmLoading: 'fetch',
731+
},
728732
},
729733
},
730734
};
@@ -736,6 +740,11 @@ const composeTargetConfig = (
736740
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
737741
// and leave them as-is in the rest of the cases.
738742
// { node: { __dirname: ..., __filename: ... } }
743+
output: {
744+
chunkLoading: 'require',
745+
workerChunkLoading: 'async-node',
746+
wasmLoading: 'async-node',
747+
},
739748
},
740749
},
741750
output: {

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
119119
},
120120
[Function],
121121
{
122+
"output": {
123+
"chunkLoading": "import",
124+
"wasmLoading": "fetch",
125+
"workerChunkLoading": "import",
126+
},
122127
"target": [
123128
"web",
124129
],
@@ -248,6 +253,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
248253
},
249254
[Function],
250255
{
256+
"output": {
257+
"chunkLoading": "import",
258+
"wasmLoading": "fetch",
259+
"workerChunkLoading": "import",
260+
},
251261
"target": [
252262
"web",
253263
],
@@ -371,6 +381,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
371381
},
372382
[Function],
373383
{
384+
"output": {
385+
"chunkLoading": "import",
386+
"wasmLoading": "fetch",
387+
"workerChunkLoading": "import",
388+
},
374389
"target": [
375390
"web",
376391
],

0 commit comments

Comments
 (0)