forked from Mirrors/elk
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.'
This commit is contained in:
parent
842102cea4
commit
45b6e39b6e
2 changed files with 29 additions and 0 deletions
28
modules/purge-comments.ts
Normal file
28
modules/purge-comments.ts
Normal 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 }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue