css-expand is a CSS compiler with extra functions
// As a CommonJs library
const {convertCascadedCssToCss} = require("css-expand");
// or as an ES module
import {convertCascadedCssToCss} from "css-expand";
<script src="./css-expand/dist/css-expand.min.mjs" type="module" />
const {convertCascadedCssToCss} = require("css-expand");
const result = convertCascadedCssToCss(`
.selector1
{
margin: 0;
background-color: slategray;
.nested1, .nested2
{
margin: 2px;
}
}`);
.selector1 {
margin: 0;
background-color: slategray;
}
.selector1 .nested1, .selector1 .nested2 {
margin: 2px;
}
import {convertCascadedCssToCss} from "css-expand";
const result = convertCascadedCssToCss(`
.selector1
{
background-color: slategray;
&.win
{
margin: 2px;
}
}`);
.selector1
{
background-color: slategray;
}
.selector1.win
{
margin: 2px;
}
import {convertCascadedCssToCss} from "./dist/css-expand.min.mjs";
const result = convertCascadedCssToCss(`
.selector1 { background-color: slategray;
&.win
{
margin: 2px;
}
}`);
console.log(result);
You can transform extremely simple sass (no vars, no mixins, only the cascading feature) file to css
css-expand --source "example1.scss" --target "/out.css"
📁 package
│
└───📁 cjs
│ │
│ │ 📝 css-expand.cjs ⇽ CJS version - 3.6k minified
│ │
└───📁 esm
│ │
│ │ 📝 index.mjs ⇽ ESM version - 3.6k minified
│ │
└───📁 dist
│ │
│ │ 📝 css-expand.min.mjs ⇽ Browser version - 4.4k minified
│ │