77 */
88
99import MiniCssExtractPlugin from 'mini-css-extract-plugin' ;
10- import * as fs from 'node:fs' ;
1110import * as path from 'node:path' ;
1211import { pathToFileURL } from 'node:url' ;
1312import type { FileImporter } from 'sass' ;
@@ -19,6 +18,7 @@ import {
1918import { SassLegacyWorkerImplementation } from '../../sass/sass-service-legacy' ;
2019import { WebpackConfigOptions } from '../../utils/build-options' ;
2120import { useLegacySass } from '../../utils/environment-options' ;
21+ import { findTailwindConfigurationFile } from '../../utils/tailwind' ;
2222import {
2323 AnyComponentStyleBudgetChecker ,
2424 PostcssCliResources ,
@@ -34,8 +34,8 @@ import {
3434} from '../utils/helpers' ;
3535
3636// eslint-disable-next-line max-lines-per-function
37- export function getStylesConfig ( wco : WebpackConfigOptions ) : Configuration {
38- const { root, buildOptions, logger } = wco ;
37+ export async function getStylesConfig ( wco : WebpackConfigOptions ) : Promise < Configuration > {
38+ const { root, buildOptions, logger, projectRoot } = wco ;
3939 const extraPlugins : Configuration [ 'plugins' ] = [ ] ;
4040
4141 extraPlugins . push ( new AnyComponentStyleBudgetChecker ( buildOptions . budgets ) ) ;
@@ -86,13 +86,13 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
8686 // Only load Tailwind CSS plugin if configuration file was found.
8787 // This acts as a guard to ensure the project actually wants to use Tailwind CSS.
8888 // The package may be unknowningly present due to a third-party transitive package dependency.
89- const tailwindConfigPath = getTailwindConfigPath ( wco ) ;
89+ const tailwindConfigPath = await findTailwindConfigurationFile ( root , projectRoot ) ;
9090 if ( tailwindConfigPath ) {
9191 let tailwindPackagePath ;
9292 try {
93- tailwindPackagePath = require . resolve ( 'tailwindcss' , { paths : [ wco . root ] } ) ;
93+ tailwindPackagePath = require . resolve ( 'tailwindcss' , { paths : [ root ] } ) ;
9494 } catch {
95- const relativeTailwindConfigPath = path . relative ( wco . root , tailwindConfigPath ) ;
95+ const relativeTailwindConfigPath = path . relative ( root , tailwindConfigPath ) ;
9696 logger . warn (
9797 `Tailwind CSS configuration file found (${ relativeTailwindConfigPath } )` +
9898 ` but the 'tailwindcss' package is not installed.` +
@@ -315,24 +315,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
315315 } ;
316316}
317317
318- function getTailwindConfigPath ( { projectRoot, root } : WebpackConfigOptions ) : string | undefined {
319- // A configuration file can exist in the project or workspace root
320- // The list of valid config files can be found:
321- // https://github.com/tailwindlabs/tailwindcss/blob/8845d112fb62d79815b50b3bae80c317450b8b92/src/util/resolveConfigPath.js#L46-L52
322- const tailwindConfigFiles = [ 'tailwind.config.js' , 'tailwind.config.cjs' ] ;
323- for ( const basePath of [ projectRoot , root ] ) {
324- for ( const configFile of tailwindConfigFiles ) {
325- // Irrespective of the name project level configuration should always take precedence.
326- const fullPath = path . join ( basePath , configFile ) ;
327- if ( fs . existsSync ( fullPath ) ) {
328- return fullPath ;
329- }
330- }
331- }
332-
333- return undefined ;
334- }
335-
336318function getSassLoaderOptions (
337319 root : string ,
338320 implementation : SassWorkerImplementation | SassLegacyWorkerImplementation ,
@@ -399,7 +381,7 @@ function getSassResolutionImporter(
399381 root : string ,
400382 preserveSymlinks : boolean ,
401383) : FileImporter < 'async' > {
402- const commonResolverOptions : Parameters < typeof loaderContext [ 'getResolve' ] > [ 0 ] = {
384+ const commonResolverOptions : Parameters < ( typeof loaderContext ) [ 'getResolve' ] > [ 0 ] = {
403385 conditionNames : [ 'sass' , 'style' ] ,
404386 mainFields : [ 'sass' , 'style' , 'main' , '...' ] ,
405387 extensions : [ '.scss' , '.sass' , '.css' ] ,
0 commit comments