CSS

CSS is a first-class citizen with Rspack. Rspack has the ability to handle CSS out-of-box, so additional configuration isn't required.

By default, files ending in *.css are treated as CSS types. Files ending in *.module.css are treated as CSS Modules module types.

If you're migrating from Webpack, you can remove the css-loader or style-loader components from your configuration to use Rspack's built-in CSS processing capabilities, as described in migration guide.

CSS Modules

By default, Rspack treats files with a *.module.css extension as CSS Modules. You can import them into your JavaScript files, and then access each class defined in the CSS file as an export from the module.

index.module.css
.red {
  color: red;
}

You can use namespace import:

index.js
import * as styles from './index.module.css';
document.getElementById('element').className = styles.red;

You can also use named import:

import { red } from './index.module.css';
document.getElementById('element').className = red;

To enable default imports in Rspack, you need to set namedExports to false in your rspack.config.js file. This allows you, when using CSS Modules, to import the entire style module by default import, in addition to namespace imports and named imports:

rspack.config.js
module.exports = {
  module: {
    parser: {
      'css/auto': {
        namedExports: false,
      },
    },
  },
};

Now you can use default import:

import styles from './index.module.css';
document.getElementById('element').className = styles.red;

For more on CSS Modules configuration, please refer to module.parser.css.

PostCSS

Rspack supports postcss-loader, which you can configure like this:

npm
yarn
pnpm
bun
npm add postcss postcss-loader -D
rspack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                // ...
              },
            },
          },
        ],
        // set to 'css/auto' if you want to support '*.module.css' as CSS Module, otherwise set type to 'css'
        type: 'css/auto',
      },
    ],
  },
};

The above configuration will have all *.css files processed by postcss-loader. The output will be passed to Rspack for CSS post-processing.

Sass

Rspack supports sass-loader, which you can configure like this:

npm
yarn
pnpm
bun
npm add sass-embedded sass-loader -D
rspack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.(sass|scss)$/,
        use: [
          {
            loader: 'sass-loader',
            options: {
              // using `modern-compiler` and `sass-embedded` together significantly improve build performance,
              // requires `sass-loader >= 14.2.1`
              api: 'modern-compiler',
              implementation: require.resolve('sass-embedded'),
            },
          },
        ],
        // set to 'css/auto' if you want to support '*.module.(scss|sass)' as CSS Module, otherwise set type to 'css'
        type: 'css/auto',
      },
    ],
  },
};

The above configuration runs all *.sass and *.scss files through the sass-loader and passes the resulting results to Rspack for CSS post-processing.

Less

Rspack supports less-loader, which you can configure like this:

npm
yarn
pnpm
bun
npm add less less-loader -D
rspack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.less$/,
        use: [
          {
            loader: 'less-loader',
            options: {
              // ...
            },
          },
        ],
        // set to 'css/auto' if you want to support '*.module.less' as CSS Module, otherwise set type to 'css'
        type: 'css/auto',
      },
    ],
  },
};

The above configuration runs all *.less files through the less-loader and passes the generated results to Rspack for CSS post-processing.

Tailwind CSS

Tailwind CSS is a utility-first CSS framework packed with classes that can be composed to build any design, directly in your markup.

Installing Tailwind CSS as a PostCSS plugin is the most seamless way to integrate it with Rspack.

Install Tailwind CSS

Please install tailwindcss,autoprefixer,postcss and postcss-loader in your project.

npm
yarn
pnpm
bun
npm add tailwindcss autoprefixer postcss postcss-loader -D

Configure Tailwind CSS

Once installed, you need to configure postcss-loader in rspack.config.js to handle CSS files, and then add tailwindcss to postcssOptions.plugins.

Here is an example configuration for handling .css files, if you need to handle .scss or .less files, you can refer to this example for modifications.

rspack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: {
                  tailwindcss: {},
                  autoprefixer: {},
                },
              },
            },
          },
        ],
        type: 'css',
      },
    ],
  },
};

At this point, you have completed the build configuration required to use Tailwind CSS in Rspack.

Next you can follow the steps in the Tailwind CSS Documentation to add the required configuration and code for Tailwind CSS and start using it.