Rspack plugins
Nx uses enhanced Rspack configuration files (e.g. rspack.config.js
). These configuration files export a plugin that takes in a rspack configuration object and returns an updated configuration object. Plugins are used by Nx to add functionality to the Rspack build.
This guide contains information on the plugins provided by Nx. For more information on customizing Rspack configuration, refer to the Nx Rspack configuration guide.
withNx
The withNx
plugin provides common configuration for the build, including TypeScript support and linking workspace libraries (via tsconfig paths).
Example
1const { composePlugins, withNx } = require('@nx/rspack');
2
3module.exports = composePlugins(withNx(), (config) => {
4 // Further customize Rspack config
5 return config;
6});
7
withWeb
The withWeb
plugin adds support for CSS/SASS/Less stylesheets, assets (such as images and fonts), and index.html
processing.
Options
stylePreprocessorOptions
Type: { includePaths: string[] }
Options to pass to style preprocessors. includePaths
is a list of paths that are included (e.g. workspace libs with stylesheets).
Example
1const { composePlugins, withNx, withWeb } = require('@nx/rspack');
2
3module.exports = composePlugins(
4 // always pass withNx() first
5 withNx(),
6 // add web functionality
7 withWeb({
8 stylePreprocessorOptions: ['ui/src'],
9 }),
10 (config) => {
11 // Further customize Rspack config
12 return config;
13 }
14);
15
withReact
The withReact
plugin adds support for React JSX and Fast Refresh
Example
1const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
3module.exports = composePlugins(
4 withNx(), // always pass withNx() first
5 withReact({
6 stylePreprocessorOptions: ['ui/src'],
7 }),
8 (config) => {
9 // Further customize Rspack config
10 return config;
11 }
12);
13