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

@sylphx/babel-plugin-silk

v2.0.6

Published

Babel plugin for zero-runtime Silk CSS-in-TypeScript compilation

Readme

@sylphx/babel-plugin-silk

Zero-runtime Babel plugin for Silk CSS-in-TypeScript

Compiles css() calls to static class names at build-time, achieving true zero-runtime overhead.

Features

  • True Zero Runtime for static styles
  • Atomic CSS generation (one class per property)
  • Partial Compilation for mixed static/dynamic styles
  • Production Optimization with short class names
  • Framework Agnostic works with any bundler

Installation

npm install --save-dev @sylphx/babel-plugin-silk
# or
bun add --dev @sylphx/babel-plugin-silk

Usage

Babel Configuration

{
  "plugins": ["@sylphx/babel-plugin-silk"]
}

With Options

{
  "plugins": [
    [
      "@sylphx/babel-plugin-silk",
      {
        "production": true,
        "classPrefix": "",
        "importSources": ["@sylphx/silk"]
      }
    ]
  ]
}

How It Works

Static Styles (Full Compilation)

// Input
import { css } from '@sylphx/silk'
const button = css({ bg: 'red', p: 4 })

// Output (Development)
const button = 'silk_bg_red_a7f3 silk_p_4_b2e1'

// Output (Production - optimal compression)
const button = 'ka5tyn p2rk1o'

// Generated CSS (Development)
.silk_bg_red_a7f3 { background-color: red; }
.silk_p_4_b2e1 { padding: 1rem; }

// Generated CSS (Production - minified)
.ka5tyn{background-color:red}.p2rk1o{padding:1rem}

Dynamic Styles (Partial Compilation)

// Input
const button = css({ bg: props.color, p: 4 })

// Output
const button = css({ bg: props.color }, 'silk_p_4_b2e1')

// Generated CSS
.silk_p_4_b2e1 { padding: 1rem; }

Static properties are extracted at build-time, dynamic properties remain at runtime.

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | production | boolean | false | Enable production optimizations (6-7 char hashes) | | classPrefix | string | 'silk' (dev), none (prod) | Class name prefix for branding | | importSources | string[] | ['@sylphx/silk'] | Import sources to transform | | functions | string[] | ['css'] | Function names to transform |

Production Class Names

In production mode, class names are optimized for minimal file size using Base-36 hashes:

// No prefix (optimal compression: 6-7 chars)
{ production: true }
// Output: .hgv0lpf, .yfr0d6, .ka5tyn

// Custom prefix (branding support)
{ production: true, classPrefix: 'app' }
// Output: .apphgv0lpf, .appyfr0d6, .appka5tyn

CSS Identifier Compliance: Leading digits (0-9) are automatically mapped to letters (g-p) to ensure valid CSS identifiers. This maintains optimal compression while guaranteeing 100% browser compatibility.

Integration with Bundlers

Vite

// vite.config.ts
import { defineConfig } from 'vite'
import { transformSync } from '@babel/core'
import babelPluginSilk from '@sylphx/babel-plugin-silk'

export default defineConfig({
  plugins: [
    {
      name: 'vite-plugin-silk',
      transform(code, id) {
        if (!id.endsWith('.tsx') && !id.endsWith('.ts')) return null

        const result = transformSync(code, {
          filename: id,
          plugins: [babelPluginSilk],
        })

        // Extract CSS from metadata
        const css = result?.metadata?.silk?.cssRules
          .map(([_, rule]) => rule)
          .join('\n')

        return {
          code: result?.code,
          map: result?.map,
        }
      },
    },
  ],
})

Next.js

// next.config.js
module.exports = {
  experimental: {
    swcPlugins: [
      ['@sylphx/babel-plugin-silk', { production: true }]
    ]
  }
}

Webpack

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.(ts|tsx)$/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: ['@sylphx/babel-plugin-silk']
          }
        }
      }
    ]
  }
}

API

Metadata Format

The plugin emits metadata via result.metadata.silk:

interface SilkMetadata {
  cssRules: Array<[className: string, cssRule: string]>
  classNames: string[]
  version: string
}

Example

const result = transformSync(code, {
  plugins: [babelPluginSilk]
})

// Access generated CSS
const css = result.metadata.silk.cssRules
  .map(([_, rule]) => rule)
  .join('\n')

// Write to file
fs.writeFileSync('output.css', css)

Supported Features

  • ✅ Static property values
  • ✅ Spread operators (static objects)
  • ✅ Property shorthands (bg, p, m, etc.)
  • ✅ Spacing units (Tailwind-style: p: 41rem)
  • ✅ Pseudo-selectors (_hover, _focus)
  • ✅ Responsive values ({ base: '100%', md: '50%' })
  • ⏳ Container queries (coming soon)
  • ⏳ Variants and recipes (coming soon)

Limitations

  • Only transforms css() calls from configured import sources
  • Renamed imports not supported (must import as css)
  • Dynamic spreads not supported
  • Imported style objects require inline definition

Development

# Build
bun run build

# Test
bun test

# Watch mode
bun run dev

License

MIT © SylphX Ltd