Skip to content

Commit f8a46ab

Browse files
Vite: Skip parsing stylesheets with the ?commonjs-proxy flag
1 parent ac202ff commit f8a46ab

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
11-
1210
### Fixed
1311

1412
- Ensure that the `containers` JS theme key is added to the `--container-*` namespace. ([#16169](https://github.com/tailwindlabs/tailwindcss/pull/16169))
13+
- Vite: Skip parsing stylesheets with the `?commonjs-proxy` flag
1514

1615
## [4.0.3] - 2025-02-01
1716

integrations/vite/index.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,49 @@ test(
841841
},
842842
)
843843

844+
test(
845+
`does not interfere with ?commonjs-proxy modules`,
846+
{
847+
fs: {
848+
'package.json': json`
849+
{
850+
"type": "module",
851+
"dependencies": {
852+
"@tailwindcss/vite": "workspace:^",
853+
"tailwindcss": "workspace:^",
854+
"plotly.js": "^3",
855+
"vite": "^6"
856+
}
857+
}
858+
`,
859+
'vite.config.ts': ts`
860+
import tailwindcss from '@tailwindcss/vite'
861+
import { defineConfig } from 'vite'
862+
863+
export default defineConfig({
864+
build: { cssMinify: false },
865+
plugins: [tailwindcss()],
866+
})
867+
`,
868+
'index.html': html`
869+
<head>
870+
<script type="module" src="./src/index.js"></script>
871+
</head>
872+
`,
873+
'src/index.js': js`import Plotly from 'plotly.js/lib/core'`,
874+
},
875+
},
876+
async ({ exec, expect, fs }) => {
877+
await exec('pnpm vite build')
878+
879+
let files = await fs.glob('dist/**/*.css')
880+
expect(files).toHaveLength(1)
881+
let [filename] = files[0]
882+
883+
await fs.expectFileToContain(filename, [candidate`maplibregl-map`])
884+
},
885+
)
886+
844887
function firstLine(str: string) {
845888
return str.split('\n')[0]
846889
}

packages/@tailwindcss-vite/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import path from 'node:path'
77
import type { Plugin, ResolvedConfig, Rollup, Update, ViteDevServer } from 'vite'
88

99
const DEBUG = env.DEBUG
10-
const SPECIAL_QUERY_RE = /[?&](raw|url)\b/
10+
const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/
11+
const COMMON_JS_PROXY_RE = /\?commonjs-proxy/
1112
const INLINE_STYLE_ID_RE = /[?&]index\=\d+\.css$/
1213

1314
const IGNORED_DEPENDENCIES = ['tailwind-merge']
@@ -315,8 +316,9 @@ function isPotentialCssRootFile(id: string) {
315316
let isCssFile =
316317
(extension === 'css' || id.includes('&lang.css') || id.match(INLINE_STYLE_ID_RE)) &&
317318
// Don't intercept special static asset resources
318-
!SPECIAL_QUERY_RE.test(id)
319-
319+
!SPECIAL_QUERY_RE.test(id) &&
320+
!COMMON_JS_PROXY_RE.test(id)
321+
if (isCssFile) console.log(id)
320322
return isCssFile
321323
}
322324

0 commit comments

Comments
 (0)