diff --git a/viteroll/examples/ssr/src/entry-server.tsx b/viteroll/examples/ssr/src/entry-server.tsx index f536333..fadbfb0 100644 --- a/viteroll/examples/ssr/src/entry-server.tsx +++ b/viteroll/examples/ssr/src/entry-server.tsx @@ -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(); res.setHeader("content-type", "text/html"); // TODO: transformIndexHtml? diff --git a/viteroll/viteroll.ts b/viteroll/viteroll.ts index ded6e04..9bfd13f 100644 --- a/viteroll/viteroll.ts +++ b/viteroll/viteroll.ts @@ -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) { @@ -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) {