1
0
elk/modules/purge-comments.ts
renovate[bot] 0fba07e6e5
chore(deps): update dependency @antfu/eslint-config to ^2.19.0 (#2726)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
2024-08-16 14:52:08 +00:00

29 lines
648 B
TypeScript

import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import MagicString from 'magic-string'
export default defineNuxtModule({
meta: {
name: 'purge-comments',
},
setup() {
addVitePlugin({
name: 'purge-comments',
enforce: 'pre',
transform: (code, id) => {
if (!id.endsWith('.vue') || !code.includes('<!--'))
return
const s = new MagicString(code)
s.replace(/<!--.*?-->/gs, '')
if (s.hasChanged()) {
return {
code: s.toString(),
map: s.generateMap({ source: id, includeContent: true }),
}
}
},
})
},
})