From dd7479c76606fe7262c3eefa34cd33df1e4ca3aa Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 9 Dec 2024 11:45:04 +0100 Subject: [PATCH 1/2] skip creating a compiler for CSS files that should not be processed --- packages/@tailwindcss-postcss/src/index.ts | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/@tailwindcss-postcss/src/index.ts b/packages/@tailwindcss-postcss/src/index.ts index a58820e7140a..52a1e2efac1b 100644 --- a/packages/@tailwindcss-postcss/src/index.ts +++ b/packages/@tailwindcss-postcss/src/index.ts @@ -63,6 +63,29 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin { postcssPlugin: 'tailwindcss', async Once(root, { result }) { env.DEBUG && console.time('[@tailwindcss/postcss] Total time in @tailwindcss/postcss') + + // Bail out early if this is guaranteed to be a non-Tailwind CSS file. + { + let canBail = true + root.walkAtRules((node) => { + if ( + node.name === 'import' || + node.name === 'theme' || + node.name === 'config' || + node.name === 'plugin' || + node.name === 'apply' + ) { + canBail = false + return false + } + }) + if (canBail) { + env.DEBUG && + console.timeEnd('[@tailwindcss/postcss] Total time in @tailwindcss/postcss') + return + } + } + let inputFile = result.opts.from ?? '' let context = getContextFromCache(inputFile, opts) let inputBasePath = path.dirname(path.resolve(inputFile)) From 176608b6a4b0995266537861d22e30bab1c87070 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 9 Dec 2024 11:47:49 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c075a947fe..1e50df2a35a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix dependency related warnings when using `@tailwindcss/postcss` on Windows ([#15321](https://github.com/tailwindlabs/tailwindcss/pull/15321)) +- Skip creating a compiler for CSS files that should not be processed ([#15340](https://github.com/tailwindlabs/tailwindcss/pull/15340)) ## [4.0.0-beta.6] - 2024-12-06 @@ -749,3 +750,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Move the CLI into a separate `@tailwindcss/cli` package ([#13095](https://github.com/tailwindlabs/tailwindcss/pull/13095)) ## [4.0.0-alpha.1] - 2024-03-06 +