npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unifycss/core

v1.1.0

Published

Core compiler engine, scanner, token generator & plugin system for UnifyCSS

Readme

@unifycss/core

Core compiler engine, content scanner, design token processor, and plugin system for UnifyCSS.

This is the foundation that powers all UnifyCSS integrations — Vite, Next.js, PostCSS, Webpack, and CLI all build on top of @unifycss/core.

npm version npm downloads License: MIT


Table of Contents


When to Use @unifycss/core

Use @unifycss/core directly when:

  • Building a custom integration with a bundler or framework not officially supported.
  • Writing scripts or CI tools that need to compile, scan, or validate UnifyCSS output.
  • Creating a custom UnifyCSS plugin.
  • Running UnifyCSS in a Node.js environment (e.g., email template generators, static site tools).

For standard Next.js, Vite, Webpack, or PostCSS setups, use the dedicated integration packages instead.


Installation

npm install @unifycss/core
# or
pnpm add @unifycss/core
# or
yarn add @unifycss/core

Configuration File

Create unifycss.config.js in your project root:

// unifycss.config.js
/** @type {import('@unifycss/core').Config} */
export default {
  // Files to scan for class names
  content: [
    './src/**/*.{html,js,ts,jsx,tsx,vue,svelte}',
    './pages/**/*.{js,ts,jsx,tsx}',
    './components/**/*.{js,ts,jsx,tsx}',
  ],

  // Theme token overrides
  theme: {
    extend: {
      colors: {
        brand: {
          primary:  '#7c3aed',
          dark:     '#5b21b6',
          light:    '#a78bfa',
        },
        gold:       '#e8c9a0',
      },
      fontFamily: {
        sans:  '"Outfit", system-ui, sans-serif',
        mono:  '"JetBrains Mono", monospace',
      },
      borderRadius: {
        DEFAULT: '0.5rem',
        lg:      '0.75rem',
      },
      spacing: {
        '128': '32rem',
        '144': '36rem',
      },
    },
  },

  // Custom plugins
  plugins: [],

  // Enable CSS purging in production
  purge: process.env.NODE_ENV === 'production',
};

Programmatic API

loadConfig

Loads and resolves a UnifyCSS configuration file:

import { loadConfig } from '@unifycss/core';

const config = await loadConfig('./unifycss.config.js');
console.log(config.content);
// → ['./src/**/*.{html,js,ts,jsx,tsx}', ...]

Signature:

function loadConfig(configPath?: string): Promise<ResolvedConfig>

compile

Compiles UnifyCSS output CSS from a configuration and detected class names:

import { compile, loadConfig } from '@unifycss/core';

const config = await loadConfig('./unifycss.config.js');

const css = await compile({
  content: ['./src/**/*.tsx'],
  config,
  minify: process.env.NODE_ENV === 'production',
});

// Write to file
import { writeFileSync } from 'fs';
writeFileSync('./dist/unifycss.css', css);

Signature:

function compile(options: CompileOptions): Promise<string>

interface CompileOptions {
  content:  string[];            // Glob patterns of files to scan
  config?:  ResolvedConfig;      // Loaded config (or path string)
  minify?:  boolean;             // Minify output CSS
  verbose?: boolean;             // Log class detection info
}

Scanner

Scans source files and extracts unique CSS class names used:

import { Scanner } from '@unifycss/core';

const scanner = new Scanner({
  content: ['./src/**/*.{html,tsx}'],
});

// Scan files via glob
const classes = await scanner.scanFiles();
console.log([...classes]);
// → Set { 'btn-primary', 'card', 'flex', 'gap-4', 'text-gold', ... }

// Scan a raw HTML/JSX string directly
const inlineClasses = scanner.scanString(
  '<button class="btn-gold btn-gold-sm">Go</button>'
);
console.log([...inlineClasses]);
// → Set { 'btn-gold', 'btn-gold-sm' }

Generator

Generates CSS output for a specific set of detected class names:

import { Generator } from '@unifycss/core';

const generator = new Generator({
  classes: new Set(['btn-primary', 'card', 'text-gold', 'flex', 'gap-4']),
  minify: false,
});

const css = await generator.generate();
console.log(css);
// → .btn-primary { ... } .card { ... } ...

Tokens

Access and transform the design token system:

import { tokens, resolveToken } from '@unifycss/core/tokens';

// Get all default design tokens
console.log(tokens.colors.gold);
// → '#e8c9a0'

console.log(tokens.spacing[4]);
// → '1rem'

// Resolve a token with theme overrides applied
const resolved = resolveToken('colors.brand.primary', {
  colors: { brand: { primary: '#7c3aed' } },
});
console.log(resolved);
// → '#7c3aed'

Plugin System

Create custom UnifyCSS plugins to extend the class system or add new token utilities:

import type { Plugin } from '@unifycss/core';

// Plugin that adds a custom .gradient-brand utility
const gradientPlugin: Plugin = {
  name: 'gradient-brand',

  handler({ addUtilities }) {
    addUtilities({
      '.gradient-brand': {
        background: 'linear-gradient(135deg, var(--brand-primary), var(--gold))',
      },
      '.gradient-brand-vertical': {
        background: 'linear-gradient(180deg, var(--brand-primary), var(--gold))',
      },
    });
  },
};

// Use in unifycss.config.js
export default {
  content: ['./src/**/*.tsx'],
  plugins: [gradientPlugin],
};

Design Token System

@unifycss/core exports the complete UnifyCSS design token catalog:

import { tokens } from '@unifycss/core/tokens';

// Color tokens
tokens.colors.brand.primary     // '#3b82f6'
tokens.colors.gold              // '#e8c9a0'
tokens.colors.success           // '#10b981'
tokens.colors.danger            // '#ef4444'
tokens.colors.dark.base         // '#07070a'

// Spacing tokens (matches 4px grid system)
tokens.spacing[0]               // '0px'
tokens.spacing[1]               // '0.25rem'
tokens.spacing[4]               // '1rem'
tokens.spacing[8]               // '2rem'
tokens.spacing[16]              // '4rem'

// Border radius tokens
tokens.borderRadius.sm          // '0.25rem'
tokens.borderRadius.md          // '0.5rem'
tokens.borderRadius.lg          // '0.75rem'
tokens.borderRadius.full        // '9999px'

// Typography tokens
tokens.fontSize.sm              // '0.875rem'
tokens.fontSize.base            // '1rem'
tokens.fontSize['2xl']          // '1.5rem'
tokens.fontSize['6xl']          // '3.75rem'

// Shadow tokens
tokens.boxShadow.sm             // '0 1px 3px rgba(0,0,0,0.12)'
tokens.boxShadow.lg             // '0 8px 32px rgba(0,0,0,0.35)'
tokens.boxShadow.gold           // '0 0 24px rgba(232,201,160,0.3)'

Semantic Component API

import { components } from '@unifycss/core/semantic';

// List all registered semantic component names
console.log(Object.keys(components));
// → ['btn', 'btn-primary', 'btn-gold', 'card', 'badge', 'alert', 'form-input', ...]

// Get CSS for a specific component
console.log(components['btn-primary']);
// → { display: 'inline-flex', padding: '14px 32px', background: '...', ... }

License

MIT © UnifyCSS Team