| 1 | import type { Plugin } from 'vite' |
| 2 | import { readFile } from 'node:fs/promises' |
| 3 | |
| 4 | const postfixRE = /[?#].*$/ |
| 5 | function cleanUrl(url: string) { |
| 6 | return url.replace(postfixRE, '') |
| 7 | } |
| 8 | |
| 9 | /** |
| 10 | * Temporary workaround for https://github.com/microsoft/monaco-editor/issues/4712 |
| 11 | */ |
| 12 | export function createPatchMonacoSourceMapPlugin( |
| 13 | ): Plugin { |
| 14 | return { |
| 15 | name: 'slidev:patch-monaco-sourcemap', |
| 16 | enforce: 'pre', |
| 17 | load(id) { |
| 18 | if (!id.includes('node_modules/monaco-editor/esm/vs/base')) |
| 19 | return |
| 20 | return readFile(cleanUrl(id), 'utf-8') |
| 21 | }, |
| 22 | } |
| 23 | } |
| 24 |