7
7
*/
8
8
9
9
import MiniCssExtractPlugin from 'mini-css-extract-plugin' ;
10
- import * as fs from 'node:fs' ;
11
10
import * as path from 'node:path' ;
12
11
import { pathToFileURL } from 'node:url' ;
13
12
import type { FileImporter } from 'sass' ;
@@ -19,6 +18,7 @@ import {
19
18
import { SassLegacyWorkerImplementation } from '../../sass/sass-service-legacy' ;
20
19
import { WebpackConfigOptions } from '../../utils/build-options' ;
21
20
import { useLegacySass } from '../../utils/environment-options' ;
21
+ import { findTailwindConfigurationFile } from '../../utils/tailwind' ;
22
22
import {
23
23
AnyComponentStyleBudgetChecker ,
24
24
PostcssCliResources ,
@@ -34,8 +34,8 @@ import {
34
34
} from '../utils/helpers' ;
35
35
36
36
// 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 ;
39
39
const extraPlugins : Configuration [ 'plugins' ] = [ ] ;
40
40
41
41
extraPlugins . push ( new AnyComponentStyleBudgetChecker ( buildOptions . budgets ) ) ;
@@ -86,13 +86,13 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
86
86
// Only load Tailwind CSS plugin if configuration file was found.
87
87
// This acts as a guard to ensure the project actually wants to use Tailwind CSS.
88
88
// 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 ) ;
90
90
if ( tailwindConfigPath ) {
91
91
let tailwindPackagePath ;
92
92
try {
93
- tailwindPackagePath = require . resolve ( 'tailwindcss' , { paths : [ wco . root ] } ) ;
93
+ tailwindPackagePath = require . resolve ( 'tailwindcss' , { paths : [ root ] } ) ;
94
94
} catch {
95
- const relativeTailwindConfigPath = path . relative ( wco . root , tailwindConfigPath ) ;
95
+ const relativeTailwindConfigPath = path . relative ( root , tailwindConfigPath ) ;
96
96
logger . warn (
97
97
`Tailwind CSS configuration file found (${ relativeTailwindConfigPath } )` +
98
98
` but the 'tailwindcss' package is not installed.` +
@@ -315,24 +315,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
315
315
} ;
316
316
}
317
317
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
-
336
318
function getSassLoaderOptions (
337
319
root : string ,
338
320
implementation : SassWorkerImplementation | SassLegacyWorkerImplementation ,
@@ -399,7 +381,7 @@ function getSassResolutionImporter(
399
381
root : string ,
400
382
preserveSymlinks : boolean ,
401
383
) : FileImporter < 'async' > {
402
- const commonResolverOptions : Parameters < typeof loaderContext [ 'getResolve' ] > [ 0 ] = {
384
+ const commonResolverOptions : Parameters < ( typeof loaderContext ) [ 'getResolve' ] > [ 0 ] = {
403
385
conditionNames : [ 'sass' , 'style' ] ,
404
386
mainFields : [ 'sass' , 'style' , 'main' , '...' ] ,
405
387
extensions : [ '.scss' , '.sass' , '.css' ] ,
0 commit comments