Webpack plugin
for an unofficial
napi-rs
compiler that includes the StyleX SWC code transformation under the hood.
To install the package, run the following command:
npm install --save-dev @stylexswc/webpack-plugin
Please install @stylexswc/rs-compiler
if you haven't done so already:
npm install --save-dev @stylexswc/rs-compiler
Modify Webpack config. For example:
const StylexPlugin = require('@stylexswc/webpack-plugin');
const path = require('path');
const config = (env, argv) => ({
entry: {
main: './js/index.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
plugins: [
new StylexPlugin({
filename: 'styles.[contenthash].css',
dev: argv.mode === 'development',
}),
],
cache: true,
});
module.exports = config;
The plugin accepts the following configuration options:
- Type:
StyleXOptions
- Optional
- Default:
{}
- Description: StyleX compiler options that extend from
@stylexswc/rs-compiler
- Type:
string
- Optional
- Default:
'stylex.css'
- Description: Name of the output CSS file
- Type:
boolean
- Optional
- Default:
false
- Description: Enable CSS Layers support for better style isolation
- Type:
TransformOptions
- Optional
- Description: LightningCSS transform options (excluding code, filename, and visitor properties)
- Type:
boolean
- Optional
- Default:
true
- Description: Controls whether CSS should be extracted into a separate file