Skip to content

Commit 2f78a97

Browse files
CPunisherCopilot
andauthored
fix: swc-loader should not respect .swcrc (#12222)
* set swcrc to false * Add test * Update tests/rspack-test/configCases/builtin-swc-loader/swcrc/index.js Co-authored-by: Copilot <[email protected]> * Alert test case * Clippy --------- Co-authored-by: Copilot <[email protected]>
1 parent 0bfae2f commit 2f78a97

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

crates/rspack_loader_swc/src/options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl TryFrom<&str> for SwcCompilerOptionsWithAdditional {
187187
schema,
188188
source_map_ignore_list,
189189
},
190+
swcrc: false,
190191
..serde_json::from_value(serde_json::Value::Object(Default::default()))?
191192
},
192193
rspack_experiments: rspack_experiments.unwrap_or_default().into(),
@@ -218,10 +219,9 @@ mod tests {
218219
swc_options_from_native_lib.env_name
219220
);
220221
assert_eq!(swc_options_from_rspack.cwd, swc_options_from_native_lib.cwd);
221-
assert_eq!(
222-
swc_options_from_rspack.swcrc,
223-
swc_options_from_native_lib.swcrc
224-
);
222+
223+
// We dont't want swc-loader in rspack to respect swcrc
224+
assert!(!swc_options_from_rspack.swcrc);
225225
}
226226

227227
#[test]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {},
3+
"jsc": {
4+
"target": "es2015"
5+
}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const a = 42;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
it("should not respect .swcrc", () => {
2+
const { a } = require("./a.ts");
3+
expect(a).toBe(42);
4+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
resolve: {
4+
extensions: ["...", ".ts", ".tsx", ".jsx"]
5+
},
6+
module: {
7+
rules: [
8+
{
9+
test: /\.ts$/,
10+
use: [
11+
{
12+
loader: "builtin:swc-loader",
13+
options: {
14+
jsc: {
15+
parser: {
16+
syntax: "typescript"
17+
}
18+
}
19+
}
20+
}
21+
],
22+
type: "javascript/auto"
23+
},
24+
]
25+
}
26+
};

0 commit comments

Comments
 (0)