diff --git a/packages/nuxt/src/core/plugins/dev-only.ts b/packages/nuxt/src/core/plugins/dev-only.ts index 26a0147161..f1f56122d0 100644 --- a/packages/nuxt/src/core/plugins/dev-only.ts +++ b/packages/nuxt/src/core/plugins/dev-only.ts @@ -1,4 +1,3 @@ -import { stripLiteral } from 'strip-literal' import MagicString from 'magic-string' import { createUnplugin } from 'unplugin' import { type Node, parse } from 'ultrahtml' @@ -22,8 +21,7 @@ export const DevOnlyPlugin = createUnplugin((options: DevOnlyPluginOptions) => { if (!DEVONLY_COMP_SINGLE_RE.test(code)) { return } const s = new MagicString(code) - const strippedCode = stripLiteral(code) - for (const match of strippedCode.matchAll(DEVONLY_COMP_RE) || []) { + for (const match of code.matchAll(DEVONLY_COMP_RE) || []) { const ast: Node = parse(match[0]).children[0] const fallback: Node | undefined = ast.children?.find((n: Node) => n.name === 'template' && Object.values(n.attributes).includes('#fallback')) const replacement = fallback ? match[0].slice(fallback.loc[0].end, fallback.loc[fallback.loc.length - 1].start) : '' diff --git a/packages/nuxt/test/devonly.test.ts b/packages/nuxt/test/devonly.test.ts index 5275117b07..bf237ca699 100644 --- a/packages/nuxt/test/devonly.test.ts +++ b/packages/nuxt/test/devonly.test.ts @@ -56,4 +56,27 @@ describe('test devonly transform ', () => { expect(result).not.toContain('lazy-dev-only') expect(result).not.toContain('LazyDevOnly') }) + + it('should not remove class -> nuxt#24491', async () => { + const source = ` + ` + + const result = await viteTransform(source, 'some id') + + expect(result).toMatchInlineSnapshot(` + " + " + `) + }) })