Skip to content

Commit

Permalink
wip: sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 15, 2024
1 parent 39fdabd commit c5ec823
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions viteroll/examples/ssr/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { App } from "./app";
const handler: Connect.SimpleHandleFunction = (req, res) => {
const url = new URL(req.url ?? "/", "https://vite.dev");
console.log(`[SSR] ${req.method} ${url.pathname}`);
if (url.pathname === "/crash-ssr") {
throw new Error("crash-ssr");
}
const ssrHtml = ReactDOMServer.renderToString(<App />);
res.setHeader("content-type", "text/html");
// TODO: transformIndexHtml?
Expand Down
32 changes: 21 additions & 11 deletions viteroll/viteroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,23 @@ class RolldownModuleRunner {
self: this.context,
...this.context,
};
// TODO: sourcemap
code = code.replace(/^\/\/# sourceMapping.*$/m, "");
const wrapped = `'use strict';(${Object.keys(context).join(",")})=>{{
${code};
// TODO: need to re-expose runtime utilities for now
self.__toCommonJS = __toCommonJS;
self.__export = __export;
self.__toESM = __toESM;
}}`;
const fn = (0, eval)(wrapped);
// TODO: sourcemap not working?
// extract sourcemap
const sourcemap = code.match(/^\/\/# sourceMappingURL=.*/m)?.[0] ?? "";
if (sourcemap) {
code = code.replace(sourcemap, "");
}
code = `\
${code}
// TODO: need to re-expose runtime utilities for now
self.__toCommonJS = __toCommonJS;
self.__export = __export;
self.__toESM = __toESM;
//# sourceMappingSource=rolldown-module-runner
${sourcemap}
`;
// fs.writeFileSync(".dump.js", code);
const fn = new Function(...Object.keys(context), code);
try {
fn(...Object.values(context));
} catch (e) {
Expand Down Expand Up @@ -440,7 +447,10 @@ function viterollEntryPlugin(
if (viterollOptions.reactRefresh) {
output.prepend(getReactRefreshRuntimeCode());
}
return { code: output.toString(), map: output.generateMap() };
return {
code: output.toString(),
map: output.generateMap({ hires: "boundary" }),
};
}
},
generateBundle(_options, bundle) {
Expand Down

0 comments on commit c5ec823

Please sign in to comment.