Skip to content

feat: support multipleConfig #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gaoachao
Copy link

@gaoachao gaoachao commented Mar 21, 2025

Setting Tailwind config path for different entries

multipleConfig can be configured as an object where the key is the entryName and the value is the config path.
If the key cannot be found, it will fallback to config , which is the default config path.

example:

// rspack.config.js
import { TailwindRspackPlugin } from 'rsbuild-plugin-tailwindcss'

export default {
  plugins: [
    new TailwindRspackPlugin({
       multipleConfig: {
         index: './config/tailwind.index.config.js',
         main: './config/tailwind.main.config.js'
       },
    }),
  ],
}

@luhc228
Copy link
Collaborator

luhc228 commented Mar 21, 2025

Can we extend the existing config field to support an object type?

new TailwindRspackPlugin({
    // now is string type
    config: './config.js',
    // object
     config: {
       index: './config/tailwind.index.config.js',
       main: './config/tailwind.main.config.js'
     },
  })

@gaoachao
Copy link
Author

@luhc228 Thank you for your suggestion. However, according to our design, multipleConfig is intended to fallback to config, which then fallback to './tailwindcss.config.js'. If we extend config to support object, it would bypass the custom config fallback and directly default to './tailwindcss.config.js', which breaks the intended fallback chain.

@gaoachao gaoachao force-pushed the feat/add-multiple-config branch from 435417f to 582d3a3 Compare March 23, 2025 16:14
Copy link
Collaborator

@colinaaa colinaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm not a fan of the multipleConfig concept. It doesn't feel intuitive to me.

Here are some alternative methods:

  1. Support @config directive of Tailwind CSS

This is the best way since it is just how Tailwind CSS works with PostCSS and it does not need extra configuration.

To support @config we need to change processing Tailwind CSS from processAssets to a loader (so that the PostCSS knows about the current file path).

I've implemented a prototype in Tailwind CSS v4, see #17 (comment) for details.

  1. Use multiple pluginTailwindCSS

This idea came from the HtmlWebpackPlugin.

export default {
  entry: {
    foo: './src/foo.js',
    bar: './src/bar.js',
  },
  plugins: [
    new TailwindCSSRspackPlugin({
      config: './foo/tailwind.config.js',
      chunks: ['foo.css'],
    }),
    new TailwindCSSRspackPlugin({
      config: './bar/tailwind.config.js',
      chunks: ['bar.css'],
    }),
  ],
}
  1. Use config: string | ((entryName: string) => string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants