Skip to content

Commit

Permalink
Support source maps in the node loader
Browse files Browse the repository at this point in the history
This allows people to debug MDX files when using the Node.js loader.
  • Loading branch information
remcohaszing committed Mar 12, 2024
1 parent c747990 commit f648f2d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/node-loader/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ export function createLoader(options) {
if (url.protocol === 'file:' && regex.test(url.pathname)) {
const value = await fs.readFile(url)
const file = await process(new VFile({value, path: url}))
let source = String(file)
/* c8 ignore start -- not sure how to test this. */
if (file.map) {
source +=
'\n//# sourceMappingURL=data:application/json;base64,' +
Buffer.from(JSON.stringify(file.map)).toString('base64') +
'\n'
}
/* c8 ignore stop */

return {format: 'module', shortCircuit: true, source: String(file)}
return {format: 'module', shortCircuit: true, source}
}

return nextLoad(href, context)
Expand Down

0 comments on commit f648f2d

Please sign in to comment.