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
Daniel Roe 2022-11-25 14:42:26 +00:00
parent 842102cea4
commit 45b6e39b6e
No known key found for this signature in database
GPG Key ID: 22D5008E4F5D9B55
2 changed files with 29 additions and 0 deletions

View File

@ -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 }),
}
}
},
})
},
})

View File

@ -5,6 +5,7 @@ export default defineNuxtConfig({
'@unocss/nuxt', '@unocss/nuxt',
'@pinia/nuxt', '@pinia/nuxt',
'@vue-macros/nuxt', '@vue-macros/nuxt',
'~/modules/purge-comments',
], ],
experimental: { experimental: {
reactivityTransform: true, reactivityTransform: true,