fix: do not emit runtime comments
resolves 'Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.'zio/stable
parent
842102cea4
commit
45b6e39b6e
|
@ -0,0 +1,28 @@
|
|||
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(/<!--(?:.*?)-->/sg, '')
|
||||
|
||||
if (s.hasChanged()) {
|
||||
return {
|
||||
code: s.toString(),
|
||||
map: s.generateMap({ source: id, includeContent: true }),
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
|
@ -5,6 +5,7 @@ export default defineNuxtConfig({
|
|||
'@unocss/nuxt',
|
||||
'@pinia/nuxt',
|
||||
'@vue-macros/nuxt',
|
||||
'~/modules/purge-comments',
|
||||
],
|
||||
experimental: {
|
||||
reactivityTransform: true,
|
||||
|
|
Loading…
Reference in New Issue