Modern.js 3.0 recommends integrating Tailwind CSS through Rsbuild's native approach, no longer relying on the @modern-js/plugin-tailwindcss plugin, to fully utilize Rsbuild's more flexible configuration capabilities and better build experience.
The migration operations in this section only need to be performed when the project actually uses the @modern-js/plugin-tailwindcss plugin.
Remove the @modern-js/plugin-tailwindcss dependency and configuration.
2.0 Version:
import { defineConfig } from '@modern-js/app-tools';
import tailwindcssPlugin from '@modern-js/plugin-tailwindcss';
export default defineConfig({
plugins: [tailwindcssPlugin()],
});3.0 Version:
import { defineConfig } from '@modern-js/app-tools';
export default defineConfig({
plugins: [],
});Also remove the @modern-js/plugin-tailwindcss dependency from package.json.
Create or update the postcss.config.cjs file.
module.exports = {
plugins: {
tailwindcss: {},
},
};Single Configuration Case:
tailwind.config.{ts,js}, no additional processing is neededmodern.config.ts, you need to migrate Tailwind-related configurations to tailwind.config.{ts,js}Dual Configuration Case:
If both tailwind.config.{ts,js} and modern.config.ts have configurations, you need to merge the configurations from both and migrate the merged configuration to tailwind.config.{ts,js}.
Special Directory Handling:
If the project has storybook or config/html directories, you need to add them to the content in tailwind.config.{ts,js}:
export default {
content: [
'./src/**/*.{js,jsx,ts,tsx}',
'./storybook/**/*', // If storybook directory exists
'./config/html/**/*.{html,ejs,hbs}', // If config/html directory exists
],
};Change the CSS import method to the @tailwind directive approach.
2.0 Version:
@import 'tailwindcss/base.css';
@import 'tailwindcss/components.css';
@import 'tailwindcss/utilities.css';3.0 Version:
@tailwind base;
@tailwind components;
@tailwind utilities;