
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@stylexswc/nextjs-plugin
Advanced tools
Part of the StyleX SWC Plugin workspace
Next.js plugin for an unofficial
napi-rs
compiler that includes the StyleX SWC code transformation under the hood.
This package combines two solutions to enhance your Next.js development experience with StyleX:
To install the package, run the following command:
npm install --save-dev @stylexswc/nextjs-plugin
This plugin supports both Webpack and Turbopack configurations in Next.js.
For standard Next.js Webpack builds, use the default import:
const stylexPlugin = require('@stylexswc/nextjs-plugin');
module.exports = stylexPlugin({
// StyleX options here
})({
// Next.js config here
});
[!IMPORTANT] Turbopack Limitation: Turbopack does not support webpack plugins (see Next.js docs). When using Turbopack, the loader only compiles StyleX code but does not extract CSS.
You must configure the PostCSS plugin for CSS extraction. Install
@stylexswc/postcss-pluginand configure it inpostcss.config.js:// postcss.config.js module.exports = { plugins: { '@stylexswc/postcss-plugin': { rsOptions: { dev: process.env.NODE_ENV === 'development', }, }, autoprefixer: {}, }, };
For Next.js with Turbopack, use the /turbopack export:
import withStylexTurbopack from '@stylexswc/nextjs-plugin/turbopack';
export default withStylexTurbopack({
// StyleX options here same as postcss-plugin
rsOptions: {
dev: process.env.NODE_ENV === 'development',
},
})({
// Next.js config here
experimental: {
turbopack: {
// Additional Turbopack configuration if needed
},
},
});
[!NOTE] When using Turbopack, the following options are not supported and will be ignored:
useCSSLayersnextjsModetransformCssextractCSS
rsOptionsPartial<StyleXOptions>[!NOTE] New Features: The
includeandexcludeoptions are exclusive to this NAPI-RS compiler implementation and are not available in the official StyleX Babel plugin.
rsOptions.include(string | RegExp)[]rsOptions.exclude(string | RegExp)[]include pattern. Patterns are matched against paths relative to the current
working directory.stylexImportsArray<string | { as: string, from: string }>['stylex', '@stylexjs/stylex']useCSSLayersUseLayersTypefalseextractCSSbooleantruetransformCss(css: string, filePath: string | undefined) => string | Buffer | Promise<string | Buffer>const path = require('path');
const stylexPlugin = require('@stylexswc/nextjs-plugin');
const rootDir = __dirname;
module.exports = stylexPlugin({
// Add any StyleX options here
rsOptions: {
dev: process.env.NODE_ENV !== 'production',
// Include only specific directories
include: [
'app/**/*.{ts,tsx}',
'components/**/*.{ts,tsx}',
'src/**/*.{ts,tsx}',
],
// Exclude test files and API routes
exclude: ['**/*.test.*', '**/*.stories.*', '**/__tests__/**', 'app/api/**'],
aliases: {
'@/*': [path.join(rootDir, '*')],
},
unstable_moduleResolution: {
type: 'commonJS',
},
},
stylexImports: ['@stylexjs/stylex', { from: './theme', as: 'tokens' }],
useCSSLayers: true,
transformCss: async (css, filePath) => {
const postcss = require('postcss');
const result = await postcss([require('autoprefixer')]).process(css, {
from: filePath,
map: {
inline: false,
annotation: false,
},
});
return result.css;
},
})({
transpilePackages: ['@stylexjs/open-props'],
// Optionally, add any other Next.js config below
});
import path from 'path';
import withStylexTurbopack from '@stylexswc/nextjs-plugin/turbopack';
const rootDir = __dirname;
export default withStylexTurbopack({
// Add any StyleX options here
rsOptions: {
dev: process.env.NODE_ENV !== 'production',
aliases: {
'@/*': [path.join(rootDir, '*')],
},
unstable_moduleResolution: {
type: 'commonJS',
},
},
stylexImports: ['@stylexjs/stylex'],
})({
transpilePackages: ['@stylexjs/open-props'],
experimental: {
turbopack: {
// Additional Turbopack configuration if needed
},
},
// Optionally, add any other Next.js config below
});
// postcss.config.js
const path = require('path');
module.exports = {
plugins: {
'@stylexswc/postcss-plugin': {
include: [
'app/**/*.{js,jsx,ts,tsx}',
'components/**/*.{js,jsx,ts,tsx}',
],
rsOptions: {
aliases: {
'@/*': [path.join(__dirname, '*')],
},
unstable_moduleResolution: {
type: 'commonJS',
},
dev: process.env.NODE_ENV === 'development',
},
},
autoprefixer: {},
},
};
Include only specific directories:
stylexPlugin({
rsOptions: {
include: ['app/**/*.tsx', 'components/**/*.tsx'],
},
});
Exclude test and build files:
stylexPlugin({
rsOptions: {
exclude: ['**/*.test.*', '**/*.spec.*', '**/dist/**', '**/node_modules/**'],
},
});
Using regular expressions:
stylexPlugin({
rsOptions: {
include: [/app\/.*\.tsx$/, /components\/.*\.tsx$/],
exclude: [/\.test\./, /\.stories\./],
},
});
Combined include and exclude (exclude takes precedence):
stylexPlugin({
rsOptions: {
include: ['app/**/*.{ts,tsx}', 'components/**/*.{ts,tsx}'],
exclude: ['**/__tests__/**', '**/__mocks__/**', 'app/api/**'],
},
});
Exclude node_modules except specific packages:
stylexPlugin({
rsOptions: {
// Exclude all node_modules except @stylexjs/open-props
exclude: [/node_modules(?!\/@stylexjs\/open-props)/],
},
});
Transform only specific packages from node_modules:
stylexPlugin({
rsOptions: {
include: [
'app/**/*.{ts,tsx}',
'components/**/*.{ts,tsx}',
'node_modules/@stylexjs/open-props/**/*.js',
'node_modules/@my-org/design-system/**/*.js',
],
exclude: ['**/*.test.*', 'app/api/**'],
},
});
This plugin was inspired by
stylex-webpack.
MIT — see LICENSE
FAQs
StyleX NextJS plugin with NAPI-RS compiler
The npm package @stylexswc/nextjs-plugin receives a total of 4,362 weekly downloads. As such, @stylexswc/nextjs-plugin popularity was classified as popular.
We found that @stylexswc/nextjs-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.