Skip to content

Commit

Permalink
move source map declaration to its own line
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs committed Jul 16, 2024
1 parent e868ea3 commit 20d3a34
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/app/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import fs from "fs-extra";
import path from "path";
import rimraf from "rimraf";
import { fileURLToPath } from "url";
import { sourcemapNewline } from "../sourcemapNewline.mjs";

const dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -403,6 +404,7 @@ export default {
],
hook: "generateBundle",
}),
sourcemapNewline(),
],
watch: {
clearScreen: false,
Expand Down
2 changes: 2 additions & 0 deletions frontend/openchat-service-worker/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import resolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import del from "rollup-plugin-delete";
import { sourcemapNewline } from "../sourcemapNewline.mjs";

export default {
input: `./src/service_worker.ts`,
Expand All @@ -27,5 +28,6 @@ export default {
dedupe: ["@dfinity/candid"],
}),
terser(),
sourcemapNewline(),
],
};
2 changes: 2 additions & 0 deletions frontend/openchat-worker/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import resolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import del from "rollup-plugin-delete";
import { sourcemapNewline } from "../sourcemapNewline.mjs";

export default {
input: `./src/worker.ts`,
Expand All @@ -26,5 +27,6 @@ export default {
preferBuiltins: false,
}),
terser(),
sourcemapNewline(),
],
};
18 changes: 18 additions & 0 deletions frontend/sourcemapNewline.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function sourcemapNewline() {
return {
name: "sourcemap-newline",
generateBundle(_, bundle) {
for (const fileName in bundle) {
const chunk = bundle[fileName];
if (chunk.type === "chunk") {
const sourceMappingRegex = /(\/\/[@#] sourceMappingURL=.+)(\r?\n)?$/;
const match = chunk.code.match(sourceMappingRegex);

if (match) {
chunk.code = chunk.code.replace(sourceMappingRegex, "\n$1\n");
}
}
}
},
};
}

0 comments on commit 20d3a34

Please sign in to comment.