Created
December 10, 2025 11:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { NextConfig } from "next"; | |
| const nextConfig: NextConfig = { | |
| turbopack: { | |
| rules: { | |
| "*.{ts,tsx}": { | |
| loaders: ["./sample-console-log.mjs"], | |
| }, | |
| }, | |
| }, | |
| }; | |
| export default nextConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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;", ` | |
| ); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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