@@ -144,6 +144,33 @@ interface TailwindRspackPluginOptions {
144144 PostCSSLoaderOptions [ 'postcssOptions' ] ,
145145 ( loaderContext : Rspack . LoaderContext ) => void
146146 > ;
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 ;
147174}
148175
149176// From `@rollup/pluginutils`
@@ -244,14 +271,17 @@ class TailwindRspackPluginImpl {
244271 return ;
245272 }
246273 }
247-
248274 const [
249275 { default : postcss } ,
250276 { default : tailwindcss } ,
251277 configPath ,
252278 ] = await Promise . all ( [
253279 import ( 'postcss' ) ,
254- import ( 'tailwindcss' ) ,
280+ import (
281+ typeof this . options . tailwindcssPath === 'string'
282+ ? `${ pathToFileURL ( this . options . tailwindcssPath ) } `
283+ : 'tailwindcss'
284+ ) ,
255285 this . #prepareTailwindConfig(
256286 entryName ,
257287 Array . from ( entryModules ) . filter ( filter ) ,
@@ -335,6 +365,7 @@ class TailwindRspackPluginImpl {
335365 const [ configName , configContent ] = await this . #generateTailwindConfig(
336366 userConfig ,
337367 entryModules ,
368+ this . options . tailwindcssPath ,
338369 ) ;
339370 const configPath = path . resolve ( outputDir , configName ) ;
340371
@@ -343,10 +374,12 @@ class TailwindRspackPluginImpl {
343374 return configPath ;
344375 }
345376
346- async #resolveTailwindCSSVersion( ) : Promise < string > {
377+ async #resolveTailwindCSSVersion(
378+ tailwindcssPath : string | undefined ,
379+ ) : Promise < string > {
347380 const require = createRequire ( import . meta. url ) ;
348381 const pkgPath = require . resolve ( 'tailwindcss/package.json' , {
349- paths : [ this . compiler . context ] ,
382+ paths : [ tailwindcssPath ? path . dirname ( tailwindcssPath ) : this . compiler . context ] ,
350383 } ) ;
351384
352385 const content = await readFile ( pkgPath , 'utf-8' ) ;
@@ -359,8 +392,9 @@ class TailwindRspackPluginImpl {
359392 async #generateTailwindConfig(
360393 userConfig : string ,
361394 entryModules : string [ ] ,
395+ tailwindcssPath : string | undefined ,
362396 ) : Promise < [ 'tailwind.config.mjs' | 'tailwind.config.cjs' , string ] > {
363- const version = await this . #resolveTailwindCSSVersion( ) ;
397+ const version = await this . #resolveTailwindCSSVersion( tailwindcssPath ) ;
364398
365399 const { default : satisfies } = await import (
366400 'semver/functions/satisfies.js'
0 commit comments