mirror of
https://github.com/elk-zone/elk
synced 2024-11-27 14:28:10 +09:00
0fba07e6e5
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>
29 lines
648 B
TypeScript
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 }),
|
|
}
|
|
}
|
|
},
|
|
})
|
|
},
|
|
})
|