Skip to content

Commit e697872

Browse files
authored
fix(swc-loader): Propagate extra build info through swc-loader (#121)
# Summary At Canva, we use some transform steps in our webpack config before `swc-loader` runs, which collects module build info / metadata to be used in the webpack plugins stage. What we noticed is that `swc-loader` is dropping that additional build info for some reason, which means we won't be able to consume it down the line. Seems like just adding a third parameter to the `makeLoader` returned function and passing it through to the callbacks works correctly. Let me know if this change looks good!
1 parent ad417fa commit e697872

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.changeset/bright-drinks-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"swc-loader": patch
3+
---
4+
5+
Pass through incoming extra build info to output

packages/swc-loader/src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const swc = require("@swc/core");
22

33
function makeLoader() {
4-
return function (source, inputSourceMap) {
4+
return function (source, inputSourceMap, extra) {
55
// Make the loader async
66
const callback = this.async();
77
const filename = this.resourcePath;
@@ -91,15 +91,17 @@ function makeLoader() {
9191
callback(
9292
null,
9393
output.code,
94-
parseMap ? JSON.parse(output.map) : output.map
94+
parseMap ? JSON.parse(output.map) : output.map,
95+
extra
9596
);
9697
} else {
9798
swc.transform(source, programmaticOptions).then(
9899
(output) => {
99100
callback(
100101
null,
101102
output.code,
102-
parseMap ? JSON.parse(output.map) : output.map
103+
parseMap ? JSON.parse(output.map) : output.map,
104+
extra
103105
);
104106
},
105107
(err) => {

0 commit comments

Comments
 (0)