@@ -144,6 +144,33 @@ interface TailwindRspackPluginOptions {
144
144
PostCSSLoaderOptions [ 'postcssOptions' ] ,
145
145
( loaderContext : Rspack . LoaderContext ) => void
146
146
> ;
147
+
148
+ /**
149
+ * Specifies the absolute path to the tailwindcss package.
150
+ *
151
+ * By default, tailwindcss is resolved using Node.js module resolution algorithm
152
+ * starting from the project's root directory. This option allows explicit
153
+ * specification of the tailwindcss location for scenarios where automatic
154
+ * resolution fails or the resolved path is not correct, such as in monorepo.
155
+ *
156
+ * ```js
157
+ * // rspack.config.js
158
+ * import { TailwindRspackPlugin } from 'rsbuild-plugin-tailwindcss'
159
+ *
160
+ * export default {
161
+ * plugins: [
162
+ * new TailwindRspackPlugin({
163
+ * postcssOptions: {
164
+ * plugins: {
165
+ * tailwindcssPath: require.resolve('tailwindcss'),
166
+ * },
167
+ * },
168
+ * }),
169
+ * ],
170
+ * }
171
+ * ```
172
+ */
173
+ tailwindcssPath ?: string | undefined ;
147
174
}
148
175
149
176
// From `@rollup/pluginutils`
@@ -244,14 +271,17 @@ class TailwindRspackPluginImpl {
244
271
return ;
245
272
}
246
273
}
247
-
248
274
const [
249
275
{ default : postcss } ,
250
276
{ default : tailwindcss } ,
251
277
configPath ,
252
278
] = await Promise . all ( [
253
279
import ( 'postcss' ) ,
254
- import ( 'tailwindcss' ) ,
280
+ import (
281
+ typeof this . options . tailwindcssPath === 'string'
282
+ ? `${ pathToFileURL ( this . options . tailwindcssPath ) } `
283
+ : 'tailwindcss'
284
+ ) ,
255
285
this . #prepareTailwindConfig(
256
286
entryName ,
257
287
Array . from ( entryModules ) . filter ( filter ) ,
@@ -335,6 +365,7 @@ class TailwindRspackPluginImpl {
335
365
const [ configName , configContent ] = await this . #generateTailwindConfig(
336
366
userConfig ,
337
367
entryModules ,
368
+ this . options . tailwindcssPath ,
338
369
) ;
339
370
const configPath = path . resolve ( outputDir , configName ) ;
340
371
@@ -343,10 +374,12 @@ class TailwindRspackPluginImpl {
343
374
return configPath ;
344
375
}
345
376
346
- async #resolveTailwindCSSVersion( ) : Promise < string > {
377
+ async #resolveTailwindCSSVersion(
378
+ tailwindcssPath : string | undefined ,
379
+ ) : Promise < string > {
347
380
const require = createRequire ( import . meta. url ) ;
348
381
const pkgPath = require . resolve ( 'tailwindcss/package.json' , {
349
- paths : [ this . compiler . context ] ,
382
+ paths : [ tailwindcssPath ? path . dirname ( tailwindcssPath ) : this . compiler . context ] ,
350
383
} ) ;
351
384
352
385
const content = await readFile ( pkgPath , 'utf-8' ) ;
@@ -359,8 +392,9 @@ class TailwindRspackPluginImpl {
359
392
async #generateTailwindConfig(
360
393
userConfig : string ,
361
394
entryModules : string [ ] ,
395
+ tailwindcssPath : string | undefined ,
362
396
) : Promise < [ 'tailwind.config.mjs' | 'tailwind.config.cjs' , string ] > {
363
- const version = await this . #resolveTailwindCSSVersion( ) ;
397
+ const version = await this . #resolveTailwindCSSVersion( tailwindcssPath ) ;
364
398
365
399
const { default : satisfies } = await import (
366
400
'semver/functions/satisfies.js'
0 commit comments