mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
f8c6a341fb
Co-authored-by: 翠 / green <green@sapphi.red>
19 lines
544 B
TypeScript
19 lines
544 B
TypeScript
import MagicString from 'magic-string'
|
|
import type { Plugin } from 'vite'
|
|
|
|
export const transformZooWithSourcemapPlugin: () => Plugin = () => ({
|
|
name: 'sourcemap',
|
|
transform(code, id) {
|
|
if (id.includes('zoo.js')) {
|
|
const ms = new MagicString(code)
|
|
ms.append('// add comment')
|
|
return {
|
|
code: ms.toString(),
|
|
// NOTE: MagicString without `filename` option generates
|
|
// a sourcemap with `sources: ['']` or `sources: [null]`
|
|
map: ms.generateMap({ hires: true }),
|
|
}
|
|
}
|
|
},
|
|
})
|