Skip to content
AliasCSS Logo
v1.5.6
Docs / Frameworks

Frameworks

AliasCSS reads your source files as text, so it works with any framework. Run the CLI next to your dev server, or compile from a Vite plugin.

Any framework

The CLI doesn’t parse your framework, it scans text. Point input at your templates and components, import the output file once, and run the CLI in watch mode while you develop:

// aliascss.config.js
export default {
  input: ['src/**/*.{html,jsx,tsx,vue,svelte,astro}'],
  output: { location: 'src/styles/acss.css' },
};
{
  "scripts": {
    "css": "aliascss --config --watch",
    "build": "aliascss --config && vite build"
  }
}

Run npm run css in a second terminal next to your usual dev command.

React and JSX

className="…" literals are found as they are. Anything inside {…} needs the extractor wrapper:

const variants = {
  primary: String('bgc-accentRA1000 c-white --hover-bgc-accentRA1100'),
  quiet: String('bgc-transparent c-slateTheme12 --hover-bgc-slateTheme3'),
};

export function Button({ variant = 'primary', ...props }) {
  return <button className={String('d-inline-flex aic g-8px p-8px-16px br-8px ') + variants[variant]} {...props} />;
}
  • Keep every class name whole: a lookup object, never 'bgc-' + color.
  • If your project runs ESLint or Prettier with auto-fix, use a named wrapper (acss('…')) instead of String(). See Installation.
  • Put state in data- attributes and style it with [data-state=open]&… in static class strings: data-open={open ? '' : undefined}.
  • Render --as- exports and keyframes- elements inside the component that uses them, so the component is self-contained.

Vue, Svelte, Astro

class="…" works as in HTML. For classes in script or dynamic bindings (:class, class:list, class={…}), wrap each complete name in String('…').

A Vite plugin

To compile inside Vite (one process, rebuilds on save), call the compiler from a small plugin. This site uses this one:

// vite-aliascss.mjs
import compileAliasCSS from 'aliascss/lib/node/compileFile.js';

export default function aliascss(config) {
  let timer;
  const compile = () => compileAliasCSS(config);
  return {
    name: 'aliascss',
    buildStart: compile,
    configureServer(server) {
      server.watcher.on('change', (file) => {
        if (!/\.(astro|html|jsx|tsx|vue|svelte)$/.test(file)) return;
        clearTimeout(timer);
        timer = setTimeout(compile, 50);
      });
    },
  };
}
// vite.config.js (or the vite key in astro.config.mjs)
import aliascss from './vite-aliascss.mjs';
import config from './aliascss.config.js';

export default { plugins: [aliascss(config)] };

Starter kits