Style9
CSS-in-JS compiler inspired by Meta's stylex
Install / Use
/learn @johanholmerin/Style9README
style9
CSS-in-JS compiler inspired by Meta's StyleX, with near-zero runtime, atomic CSS extraction and TypeScript support. Framework agnostic.
[!NOTE] StyleX was open-sourced on 2023-12-5. Consider using that instead
Basic usage
For a complete walkthrough of the API, see Usage guide.
import style9 from 'style9';
const styles = style9.create({
blue: {
color: 'blue',
},
red: {
color: 'red'
}
});
document.body.className = styles('blue', isRed && 'red');
For the above input, the compiler will generate the following output:
/* JavaScript */
document.body.className = isRed ? 'cRCRUH ' : 'hxxstI ';
/* CSS */
.hxxstI { color: blue }
.cRCRUH { color: red }
Installation
# Yarn
yarn add style9
# npm
npm install style9
Compiler setup - required
The following is the minimally required Webpack setup for extracting styles to a CSS file. For Webpack options and Rollup, Next.js, Gatsby,Vite, and Babel plugins, see Bundler plugins.
const Style9Plugin = require('style9/webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
// Collect all styles in a single file - required
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
type: 'css/mini-extract',
// For webpack@4 remove type and uncomment the line below
// test: /\.css$/,
chunks: 'all',
enforce: true,
}
}
}
},
module: {
rules: [
{
test: /\.(tsx|ts|js|mjs|jsx)$/,
use: Style9Plugin.loader,
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
plugins: [
new Style9Plugin(),
new MiniCssExtractPlugin()
]
};
Documentation
Have a question?
Look at the FAQ, search the repo, or ask in discussions.
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
106.4kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
100.0kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
