From 45b6e39b6e7c3e864fbb8f5663148d22e5822d85 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 25 Nov 2022 14:42:26 +0000 Subject: [PATCH] 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.' --- modules/purge-comments.ts | 28 ++++++++++++++++++++++++++++ nuxt.config.ts | 1 + 2 files changed, 29 insertions(+) create mode 100644 modules/purge-comments.ts diff --git a/modules/purge-comments.ts b/modules/purge-comments.ts new file mode 100644 index 00000000..ead587d7 --- /dev/null +++ b/modules/purge-comments.ts @@ -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('/sg, '') + + if (s.hasChanged()) { + return { + code: s.toString(), + map: s.generateMap({ source: id, includeContent: true }), + } + } + }, + }) + }, +}) diff --git a/nuxt.config.ts b/nuxt.config.ts index 84832a35..f376d9e8 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -5,6 +5,7 @@ export default defineNuxtConfig({ '@unocss/nuxt', '@pinia/nuxt', '@vue-macros/nuxt', + '~/modules/purge-comments', ], experimental: { reactivityTransform: true,