@@ -10,8 +10,70 @@ import {
1010 test ,
1111 ts ,
1212 txt ,
13+ yaml ,
1314} from '../utils'
1415
16+ const browserCssPluginFixture = {
17+ 'package.json' : json `
18+ {
19+ "type": "module",
20+ "dependencies": {
21+ "@tailwindcss/vite": "workspace:^",
22+ "plugin-browser-css": "workspace:*",
23+ "tailwindcss": "workspace:^"
24+ },
25+ "devDependencies": {
26+ "vite": "^8"
27+ }
28+ }
29+ ` ,
30+ 'pnpm-workspace.yaml' : yaml `
31+ packages:
32+ - packages/*
33+ ` ,
34+ 'packages/plugin-browser-css/package.json' : json `
35+ {
36+ "name": "plugin-browser-css",
37+ "version": "1.0.0",
38+ "type": "module",
39+ "main": "./index.js",
40+ "module": "./index.js",
41+ "browser": "./browser.css"
42+ }
43+ ` ,
44+ 'packages/plugin-browser-css/index.js' : js `
45+ export default function ({ addUtilities }) {
46+ addUtilities({ '.browser-css-plugin': { 'border-bottom': '1px solid green' } })
47+ }
48+ ` ,
49+ 'packages/plugin-browser-css/browser.css' : css `
50+ .should-not-be-loaded-as-a-plugin {
51+ display: none;
52+ }
53+ ` ,
54+ 'vite.config.ts' : ts `
55+ import tailwindcss from '@tailwindcss/vite'
56+ import { defineConfig } from 'vite'
57+
58+ export default defineConfig({
59+ build: { cssMinify: false },
60+ plugins: [tailwindcss()],
61+ })
62+ ` ,
63+ 'index.html' : html `
64+ <head>
65+ <link rel="stylesheet" href="./src/index.css" />
66+ </head>
67+ <body>
68+ <div class="browser-css-plugin">Hello, world!</div>
69+ </body>
70+ ` ,
71+ 'src/index.css' : css `
72+ @import 'tailwindcss';
73+ @plugin 'plugin-browser-css';
74+ ` ,
75+ }
76+
1577test (
1678 'resolves tsconfig paths in production build' ,
1779 {
@@ -288,6 +350,45 @@ test(
288350 } ,
289351)
290352
353+ test (
354+ 'resolves package plugins to JS entries in production build when browser points to CSS' ,
355+ {
356+ fs : browserCssPluginFixture ,
357+ } ,
358+ async ( { fs, exec, expect } ) => {
359+ await exec ( 'pnpm vite build' )
360+
361+ let files = await fs . glob ( 'dist/**/*.css' )
362+ expect ( files ) . toHaveLength ( 1 )
363+ let [ filename ] = files [ 0 ]
364+
365+ await fs . expectFileToContain ( filename , [ candidate `browser-css-plugin` ] )
366+ } ,
367+ )
368+
369+ test (
370+ 'resolves package plugins to JS entries in dev mode when browser points to CSS' ,
371+ {
372+ fs : browserCssPluginFixture ,
373+ } ,
374+ async ( { spawn, expect } ) => {
375+ let process = await spawn ( 'pnpm vite dev' )
376+ await process . onStdout ( ( m ) => m . includes ( 'ready in' ) )
377+
378+ let url = ''
379+ await process . onStdout ( ( m ) => {
380+ let match = / L o c a l : \s * ( h t t p .* ) \/ / . exec ( m )
381+ if ( match ) url = match [ 1 ]
382+ return Boolean ( url )
383+ } )
384+
385+ await retryAssertion ( async ( ) => {
386+ let styles = await fetchStyles ( url , '/index.html' )
387+ expect ( styles ) . toContain ( candidate `browser-css-plugin` )
388+ } )
389+ } ,
390+ )
391+
291392describe . each ( [ 'postcss' , 'lightningcss' ] ) ( '%s' , ( transformer ) => {
292393 test (
293394 'resolves aliases in production build' ,
0 commit comments