Skip to content

Commit

Permalink
Create sourcemaps for the relay plugin transformation
Browse files Browse the repository at this point in the history
Vite tracks sourcemap transformation of its plugins if they return a source map. Since the babel-plugin-relay alters the sourcecode also the source map of the transformation needs to be returned to vite for it to generate the correct sourcemaps of all transformations
  • Loading branch information
tmair committed Dec 8, 2022
1 parent 8a96602 commit 4e2313d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import { transformSync } from "@babel/core";
export default {
name: "vite:relay",
transform(src, id) {
let code = src;

if (/.(t|j)sx?/.test(id) && src.includes("graphql`")) {
const out = transformSync(src, {
plugins: [["babel-plugin-relay"]],
code: true,
filename: id,
sourceMaps: true,
});

if (!out?.code) {
throw new Error(`vite-plugin-relay: Failed to transform ${id}`);
}

code = out.code;
}
const code = out.code;
const map = out.map;

return {
code,
map: null,
};
return {
code,
map,
};
}
},
} as PluginOption;

0 comments on commit 4e2313d

Please sign in to comment.