| 7 | * @public |
| 8 | */ |
| 9 | export function detectionGlobalPlugin(): Plugin { |
| 10 | let resolvedConfig: ResolvedConfig; |
| 11 | return { |
| 12 | name: 'vite-plugin-alphatab-global', |
| 13 | |
| 14 | configResolved(config) { |
| 15 | resolvedConfig = config as ResolvedConfig; |
| 16 | }, |
| 17 | |
| 18 | shouldTransformCachedModule({ code }) { |
| 19 | return code.includes(marker); |
| 20 | }, |
| 21 | |
| 22 | async transform(code, id) { |
| 23 | if (!code.includes(marker)) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const s = new MagicString(code); |
| 28 | s.replaceAll(marker, JSON.stringify(true)); |
| 29 | return { |
| 30 | code: s.toString(), |
| 31 | map: |
| 32 | resolvedConfig.command === 'build' && resolvedConfig.build.sourcemap |
| 33 | ? s.generateMap({ hires: 'boundary', source: id }) |
| 34 | : null |
| 35 | }; |
| 36 | } |
| 37 | }; |
| 38 | } |