Install @salty-css/next and withSaltyCss() — Wire the App Router and output: export Without Webpack Surgery
Install Salty CSS in a Next.js App Router Project
The fastest way to start in any framework:
npx salty-css init
The init command detects your framework, installs the right packages, creates salty.config.ts, and wires the build plugin into your existing bundler config. For most projects that's all you need.
For a manual install on Next.js, run:
npm i @salty-css/next @salty-css/react
Next App Router supports RSC out of the box.
Next.js
- In your existing Next.js repository you can run
npx salty-css initto automatically configure Salty CSS. - Create your first Salty CSS component with
npx salty-css generate [filePath](e.g.src/custom-wrapper). - Import your component for example to
page.tsxand see it working!
Manual configuration
- Install the Next.js plugin and the runtime packages:
npm i @salty-css/next @salty-css/core @salty-css/react - Create
salty.config.tsin your app directory. - Wire the plugin into your Next config:
- Next.js 15 and newer (incl. 16.2) — in
next.config.ts:import { withSaltyCss } from "@salty-css/next"; export default withSaltyCss(nextConfig); - Next.js 14 and older — in
next.config.js:const { withSaltyCss } = require("@salty-css/next"); module.exports = withSaltyCss(nextConfig);
- Next.js 15 and newer (incl. 16.2) — in
- Make sure that
salty.config.tsandnext.config.tsare in the same folder. - Build the
saltygendirectory by running your app once or via the CLI:npx salty-css build [directory]. - Import global styles from
saltygen/index.cssin some global css file:@import 'insert_path_to_index_css';.
withSaltyCss options
Both Webpack and Turbopack are supported; withSaltyCss auto-detects which one Next.js is running (next dev --turbopack sets process.env.TURBOPACK=1) and picks the matching integration. Pass a second argument to override:
withSaltyCss(nextConfig, { bundler: "auto", // 'auto' | 'webpack' | 'turbopack' — default 'auto' mode: undefined, // 'production' | 'development' — defaults to NODE_ENV dir: undefined, // project root for Turbopack; defaults to nextConfig.turbopack.root or process.cwd() });
Next App Router supports RSC out of the box.
Manual setup
If salty-css init picks the wrong framework, can't find your bundler config, or you'd rather wire things up by hand, follow the manual setup for your stack. The framework-specific snippet above includes the precise commands and config edits; the steps below are the universal shape.
-
Install the packages. Each framework needs its runtime plus the core compiler:
- Next.js:
npm i @salty-css/next @salty-css/core @salty-css/react - React + Vite:
npm i @salty-css/vite @salty-css/core @salty-css/react - React + Webpack:
npm i @salty-css/webpack @salty-css/core @salty-css/react - Astro:
npm i @salty-css/astro @salty-css/core
- Next.js:
-
Wire the bundler plugin.
withSaltyCss(nextConfig)for Next.js,saltyPlugin(__dirname)for Vite,saltyPlugin(config, __dirname)inwebpack.config.jsfor Webpack, the integration for Astro. -
Create
salty.config.tsin the same directory as your bundler config (e.g. next tonext.config.tsorvite.config.ts):import { defineConfig } from "@salty-css/react/config"; export const config = defineConfig({ // Add variables, templates, modifiers as you grow. }); -
Import the generated stylesheet. With the default
importStrategy: 'root', Salty CSS expects one stylesheet to be imported at your app root. Most framework plugins do this for you on first run; if not, add@import "../saltygen/index.css";(or the appropriate path) to your global CSS. -
Build once. Run your dev server (or
npx salty-css build) sosaltygen/exists before the first render.
Peer dependencies
You'll need:
| Package | Version | Notes |
|---|---|---|
node | 18 or newer | Required for the build pipeline (esbuild + ESM). |
typescript | 5.x | Needed because .css.ts files are evaluated through TypeScript. |
react | 18 or 19 (when using React/Next) | The @salty-css/react runtime targets modern React. |
next | 13 (App Router) or newer; tested through 16.2 | For @salty-css/next. Webpack and Turbopack both work via withSaltyCss. |
vite | 5 or newer | For @salty-css/vite. |
astro | 4 or newer | For @salty-css/astro. |
The exact ranges live in each package's peerDependencies — check package.json if you're on a fringe version.
Verify your install
After running the dev server (or npx salty-css build), confirm:
saltygen/exists at the root of the package you initialised. It should contain at leastindex.cssand asalty.config.jssnapshot.saltygen/index.cssis non-empty. A few@layerdeclarations and your reset should be there even before you write any components.- A test component renders styled. Create a
*.css.tsfile with a tiny styled component, use it on a page, and inspect the element in DevTools — you should see a class likes_xxxxand a matching rule in the Styles panel. - No build warnings about missing plugin. Salty CSS logs a warning at build time if the plugin didn't load — search your terminal output for
salty-css.
If any step fails, jump to Troubleshooting.
The compiler can't warn you about two common structural mistakes: unexported styled calls, and variants accidentally nested inside base instead of alongside it. The ESLint plugin catches both — worth setting up once.