Builtin lightningcss-loader
Lightning CSS is a high performance CSS parser, transformer and minifier written in Rust. It supports parsing and transforming many modern CSS features into syntax supported by target browsers, and also provides a better compression ratio.
Rspack provides a built-in builtin:lightningcss-loader, which is based on Lightning CSS to transform CSS. It can replace the postcss-loader and autoprefixer for CSS syntax downgrading, prefixing, and other functionalities, offering better performance.
Please note that Lightning CSS strictly requires standards-compliant CSS input. When non-standard CSS is processed by the builtin:lightningcss-loader, styles may be ignored or produce unexpected results (Undefined Behavior). To ensure that styles are correctly applied, avoid using non-standard CSS syntax or browser-specific proprietary syntax, and instead use standard CSS writing practices that conform to W3C specifications.
Example
To use builtin:lightningcss-loader in your project, you need to configure it as follows.
Type declarations
You can use the LightningcssLoaderOptions type exported by @rspack/core to enable type hints:
Options
Below are the configurations supported by builtin:lightningcss-loader. For detailed configuration, please refer to lightningcss document.
targets
- Type:
string | string[]
Browserslist query string.
Here are some examples of setting targets.
- Setting a browserslist query string:
- Setting an array of browserslist query strings:
errorRecovery
- Type:
boolean - Default:
true
Control how Lightning CSS handles invalid CSS syntax.
By default, this option is enabled, meaning that when invalid CSS rules or declarations are parsed, Lightning CSS will skip them and emit warnings, while omitting them from the final output without interrupting the compilation process.
Ignoring warnings
If you confirm that these warnings can be ignored, you can use ignoreWarnings to filter out the warnings from LightningCSS.
For example, ignore all warnings:
You can also use regular expressions to ignore specific warnings.
Disabling errorRecovery
If you set errorRecovery to false, Lightning CSS will throw a compilation error and interrupt the build process when parsing any invalid CSS syntax:

