@stylexjs/webpack-plugin
Documentation Website
https://stylexjs.com
Installation
Install the package by using:
npm install --save-dev @stylexjs/webpack-plugin
or with yarn:
yarn add --dev @stylexjs/webpack-plugin
Add the following to your webpack.config.js
const StylexPlugin = require('@stylexjs/webpack-plugin');
const path = require('path');
const config = (env, argv) => ({
entry: {
main: './src/index.js',
},
output: {
path: path.resolve(__dirname, '.build'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
],
},
plugins: [
new StylexPlugin({
filename: 'styles.[contenthash].css',
dev: argv.mode === 'development',
runtimeInjection: false,
classNamePrefix: 'x',
unstable_moduleResolution: {
type: 'commonJS',
rootDir: __dirname,
},
}),
],
cache: true,
});
module.exports = config;
Plugin Options
It inherits all options from @stylexjs/babel-plugin and can be found here 🔗. Along with other options like
fileName
fileName: string
The name of the output css file.
useCSSLayers
useCSSLayers: boolean
Enabling this option switches Stylex from using :not(#\#) to using @layers for handling CSS specificity.
babelConfig
babelConfig: {
babelrc: boolean,
plugins: PluginItem[],
presets: PluginItem[]
}
List of custom babel plugins and presets which can be used during code transformation and whether to use the .babelrc file.