Skip to content

Instantly share code, notes, and snippets.

@realamirhe
Created December 10, 2025 11:27
Show Gist options
  • Select an option

  • Save realamirhe/9a9385eb8960a31fe1ee352b65dcbca2 to your computer and use it in GitHub Desktop.

Select an option

Save realamirhe/9a9385eb8960a31fe1ee352b65dcbca2 to your computer and use it in GitHub Desktop.
Add file logging to next.js loader based on tanstack devtool console enhancer
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
turbopack: {
rules: {
"*.{ts,tsx}": {
loaders: ["./sample-console-log.mjs"],
},
},
},
};
export default nextConfig;
import path from "node:path";
export default function (source) {
const context = this.rootContext || process.cwd();
const file = path.relative(context, this.resource);
return source.replace(
/console\.log\(/g,
() => `console.log("%c[${file}] → ", "color: #03A9F4;", `
);
}
@realamirhe
Copy link
Author

here is how it is done with babel parser in the TanStack/devtools

https://github.com/TanStack/devtools/blob/main/packages/devtools-vite/src/enhance-logs.ts#L47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment