Skip to content

Commit

Permalink
fix: derive rspack.target from libConfig.syntax (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Sep 18, 2024
1 parent ed9fe5b commit 057cd87
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions e2e/cases/syntax/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ test('should downgrade class private method with output.syntax config', async ()
expect(entries.esm1).toContain('#bar');

expect(entries.cjs0).toContain('#bar');
expect(entries.cjs0).toContain('()=>{'); // test webpack runtime arrow function
expect(entries.cjs1).not.toContain('#bar');
expect(entries.cjs1).not.toContain('()=>{'); // test webpack runtime arrow function
});
21 changes: 15 additions & 6 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,17 @@ const composeSyntaxConfig = (
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.

if (syntax) {
const resolvedBrowserslist = transformSyntaxToBrowserslist(syntax, target);
return {
tools: {
rspack: (config) => {
// TODO: Rspack should could resolve `browserslist:{query}` like webpack.
// https://webpack.js.org/configuration/target/#browserslist
// Using 'es5' as a temporary solution for compatibility.
config.target = ['es5'];
return config;
config.target = resolvedBrowserslist.map(
(item) => `browserslist:${item}` as const,
);
},
},
output: {
overrideBrowserslist: transformSyntaxToBrowserslist(syntax, target),
overrideBrowserslist: resolvedBrowserslist,
},
};
}
Expand Down Expand Up @@ -725,6 +724,11 @@ const composeTargetConfig = (
tools: {
rspack: {
target: ['web'],
output: {
chunkLoading: 'import',
workerChunkLoading: 'import',
wasmLoading: 'fetch',
},
},
},
};
Expand All @@ -736,6 +740,11 @@ const composeTargetConfig = (
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
// and leave them as-is in the rest of the cases.
// { node: { __dirname: ..., __filename: ... } }
output: {
chunkLoading: 'require',
workerChunkLoading: 'async-node',
wasmLoading: 'async-node',
},
},
},
output: {
Expand Down
15 changes: 15 additions & 0 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
},
[Function],
{
"output": {
"chunkLoading": "import",
"wasmLoading": "fetch",
"workerChunkLoading": "import",
},
"target": [
"web",
],
Expand Down Expand Up @@ -248,6 +253,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
},
[Function],
{
"output": {
"chunkLoading": "import",
"wasmLoading": "fetch",
"workerChunkLoading": "import",
},
"target": [
"web",
],
Expand Down Expand Up @@ -371,6 +381,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
},
[Function],
{
"output": {
"chunkLoading": "import",
"wasmLoading": "fetch",
"workerChunkLoading": "import",
},
"target": [
"web",
],
Expand Down

0 comments on commit 057cd87

Please sign in to comment.