From 110cc9f38edc329f7628442f07419a973a31e68d Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Wed, 18 Dec 2024 16:57:02 +0100 Subject: [PATCH 1/4] Svelte post-processor --- packages/@tailwindcss-vite/src/index.ts | 124 +----------------------- 1 file changed, 1 insertion(+), 123 deletions(-) diff --git a/packages/@tailwindcss-vite/src/index.ts b/packages/@tailwindcss-vite/src/index.ts index b3c9ace1e0f5..304379419fef 100644 --- a/packages/@tailwindcss-vite/src/index.ts +++ b/packages/@tailwindcss-vite/src/index.ts @@ -79,11 +79,6 @@ export default function tailwindcss(): Plugin[] { for (let [id, root] of roots.entries()) { let module = server.moduleGraph.getModuleById(id) if (!module) { - // The module for this root might not exist yet - if (root.builtBeforeTransform) { - continue - } - // Note: Removing this during SSR is not safe and will produce // inconsistent results based on the timing of the removal and // the order / timing of transforms. @@ -184,7 +179,6 @@ export default function tailwindcss(): Plugin[] { } return [ - svelteProcessor(roots), { // Step 1: Scan source files for candidates name: '@tailwindcss/vite:scan', @@ -225,19 +219,6 @@ export default function tailwindcss(): Plugin[] { let root = roots.get(id) - // If the root was built outside of the transform hook (e.g. in the - // Svelte preprocessor), we still want to mark all dependencies of the - // root as watched files. - if (root.builtBeforeTransform) { - root.builtBeforeTransform.forEach((file) => this.addWatchFile(file)) - root.builtBeforeTransform = undefined - } - - // We only process Svelte ` `, 'src/other.css': css` .local { @apply text-red-500; - animation: 2s ease-in-out 0s infinite localKeyframes; + animation: 2s ease-in-out infinite localKeyframes; } :global(.global) { @apply text-green-500; - animation: 2s ease-in-out 0s infinite globalKeyframes; + animation: 2s ease-in-out infinite globalKeyframes; } @keyframes -global-globalKeyframes { @@ -93,18 +93,21 @@ test( }, }, async ({ exec, fs, expect }) => { - await exec('pnpm vite build') + let output = await exec('pnpm vite build') let files = await fs.glob('dist/**/*.css') expect(files).toHaveLength(1) await fs.expectFileToContain(files[0][0], [ candidate`underline`, - '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}', - /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out 0s infinite svelte-.*-localKeyframes\}/, + '.global{color:var(--color-green-500);animation:2s ease-in-out infinite globalKeyframes}', + /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out infinite svelte-.*-localKeyframes\}/, /@keyframes globalKeyframes\{/, /@keyframes svelte-.*-localKeyframes\{/, ]) + + // Should not print any warnings + expect(output).not.toContain('vite-plugin-svelte') }, ) @@ -164,20 +167,20 @@ test(

Hello {name}!

`, 'src/index.css': css` @import 'tailwindcss'; `, 'src/other.css': css` .local { @apply text-red-500; - animation: 2s ease-in-out 0s infinite localKeyframes; + animation: 2s ease-in-out infinite localKeyframes; } :global(.global) { @apply text-green-500; - animation: 2s ease-in-out 0s infinite globalKeyframes; + animation: 2s ease-in-out infinite globalKeyframes; } @keyframes -global-globalKeyframes { @@ -210,10 +213,10 @@ test( let [, css] = files[0] expect(css).toContain(candidate`underline`) expect(css).toContain( - '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}', + '.global{color:var(--color-green-500);animation:2s ease-in-out infinite globalKeyframes}', ) expect(css).toMatch( - /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out 0s infinite svelte-.*-localKeyframes\}/, + /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out infinite svelte-.*-localKeyframes\}/, ) expect(css).toMatch(/@keyframes globalKeyframes\{/) expect(css).toMatch(/@keyframes svelte-.*-localKeyframes\{/) @@ -235,10 +238,10 @@ test( let [, css] = files[0] expect(css).toContain(candidate`font-bold`) expect(css).toContain( - '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}', + '.global{color:var(--color-green-500);animation:2s ease-in-out infinite globalKeyframes}', ) expect(css).toMatch( - /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out 0s infinite svelte-.*-localKeyframes\}/, + /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out infinite svelte-.*-localKeyframes\}/, ) expect(css).toMatch(/@keyframes globalKeyframes\{/) expect(css).toMatch(/@keyframes svelte-.*-localKeyframes\{/) From 3fc70b740c189edaa8fa4db12fc4f7ce5bf90b9d Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Thu, 9 Jan 2025 10:39:37 +0100 Subject: [PATCH 3/4] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e738d386ed1d..63af8036868d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Removed `--container-prose` in favor of a deprecated `--max-width-prose` theme variable so that `*-prose` is only available for max-width utilities and only for backward compatibility ([#15439](https://github.com/tailwindlabs/tailwindcss/pull/15439)) +- Use Vite post-processor APIs for processing Svelte `