fix(vite): source mapping locations (#3624)
Mappings were wrong for a few reasons: - Missing source map generation in one babel transform - setting `compact: false` causes vite to generate incorrect mappings in `vite:import-analysis` - stack traces need to be mapped by vite Fixes https://github.com/denoland/fresh/issues/3609
This commit is contained in:
@@ -384,10 +384,10 @@ function babelTransform(
|
||||
const result = babel.transformSync(code, {
|
||||
filename: id,
|
||||
babelrc: false,
|
||||
sourceMaps: "inline",
|
||||
sourceMaps: "both",
|
||||
presets: presets,
|
||||
plugins: [httpAbsolute(url)],
|
||||
compact: true,
|
||||
compact: false,
|
||||
});
|
||||
|
||||
if (result !== null && result.code) {
|
||||
|
||||
@@ -72,6 +72,12 @@ export function devServer(): Plugin[] {
|
||||
try {
|
||||
const mod = await server.ssrLoadModule("fresh:server_entry");
|
||||
const req = createRequest(nodeReq, nodeRes);
|
||||
mod.setErrorInterceptor((err: unknown) => {
|
||||
if (err instanceof Error) {
|
||||
server.ssrFixStacktrace(err);
|
||||
}
|
||||
});
|
||||
|
||||
const res = (await mod.default.fetch(req)) as Response;
|
||||
|
||||
// Collect css eagerly to avoid FOUC. This is a workaround for
|
||||
@@ -101,6 +107,9 @@ export function devServer(): Plugin[] {
|
||||
|
||||
await sendResponse(nodeRes, res);
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
server.ssrFixStacktrace(err);
|
||||
}
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,9 +50,10 @@ export function patches(): Plugin {
|
||||
const res = babel.transformSync(code, {
|
||||
filename: id,
|
||||
babelrc: false,
|
||||
compact: true,
|
||||
compact: false,
|
||||
plugins,
|
||||
presets,
|
||||
sourceMaps: "both",
|
||||
});
|
||||
|
||||
if (res?.code) {
|
||||
|
||||
@@ -89,7 +89,12 @@ export function registerStaticFile(prepared) {
|
||||
|
||||
if (isDev) {
|
||||
code = `import "preact/debug";
|
||||
import { setErrorInterceptor as internalErrorIntercept } from "fresh/internal";
|
||||
${code}
|
||||
|
||||
export function setErrorInterceptor(fn) {
|
||||
internalErrorIntercept(app, fn);
|
||||
}
|
||||
if (import.meta.hot) import.meta.hot.accept();`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user