@@ -427,6 +427,92 @@ for (let transformer of ['postcss', 'lightningcss']) {
427
427
} )
428
428
} ,
429
429
)
430
+
431
+ test (
432
+ `source(none) disables looking at the module graph` ,
433
+ {
434
+ fs : {
435
+ 'package.json' : json `{}` ,
436
+ 'pnpm-workspace.yaml' : yaml `
437
+ #
438
+ packages :
439
+ - project- a
440
+ ` ,
441
+ 'project-a/package.json' : txt `
442
+ {
443
+ "type" : "module" ,
444
+ "dependencies" : {
445
+ "@tailwindcss/vite" : "workspace:^" ,
446
+ "tailwindcss" : "workspace:^"
447
+ },
448
+ "devDependencies" : {
449
+ ${ transformer === 'lightningcss' ? `"lightningcss": "^1.26.0",` : '' }
450
+ "vite" : "^5.3.5"
451
+ }
452
+ }
453
+ ` ,
454
+ 'project-a/vite.config.ts' : ts `
455
+ import tailwindcss from '@tailwindcss/vite'
456
+ import { defineConfig } from 'vite'
457
+
458
+ export default defineConfig ({
459
+ css : ${ transformer === 'postcss' ? '{}' : "{ transformer: 'lightningcss' }" } ,
460
+ build : { cssMinify : false },
461
+ plugins : [tailwindcss ()],
462
+ })
463
+ ` ,
464
+ 'project-a/index.html' : html `
465
+ <head>
466
+ <link rel= "stylesheet" href = "./src/index.css" / >
467
+ </ head>
468
+ <body>
469
+ <div class= "underline m-2" > Hello , world !</ div>
470
+ </ body>
471
+ ` ,
472
+ 'project-a/src/index.css' : css `
473
+ @import 'tailwindcss' source (none);
474
+ @source '../../project-b/src/**/*.html' ;
475
+ ` ,
476
+ 'project-b/src/index.html' : html `
477
+ <div class= "flex" / >
478
+ ` ,
479
+ 'project-b/src/index.js' : js `
480
+ const className = "content-['project-b/src/index.js']"
481
+ module .exports = { className }
482
+ ` ,
483
+ } ,
484
+ } ,
485
+ async ( { root, fs, exec } ) => {
486
+ console . log ( await exec ( 'pnpm vite build' , { cwd : path . join ( root , 'project-a' ) } ) )
487
+
488
+ let files = await fs . glob ( 'project-a/dist/**/*.css' )
489
+ expect ( files ) . toHaveLength ( 1 )
490
+ let [ filename ] = files [ 0 ]
491
+
492
+ // `underline` and `m-2` are only present from files in the module graph
493
+ // which we've explicitly disabled with source(none) so they should not
494
+ // be present
495
+ await fs . expectFileNotToContain ( filename , [
496
+ //
497
+ candidate `underline` ,
498
+ candidate `m-2` ,
499
+ ] )
500
+
501
+ // The files from `project-b` should be included because there is an
502
+ // explicit `@source` directive for it
503
+ await fs . expectFileToContain ( filename , [
504
+ //
505
+ candidate `flex` ,
506
+ ] )
507
+
508
+ // The explicit source directive only covers HTML files, so the JS file
509
+ // should not be included
510
+ await fs . expectFileNotToContain ( filename , [
511
+ //
512
+ candidate `content- ['project-b/src/index.js' ]` ,
513
+ ] )
514
+ } ,
515
+ )
430
516
} )
431
517
}
432
518
0 commit comments