Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: derive rspack.target from libConfig.syntax #213

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {
Timeless0911 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading