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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pandabox/unplugin-panda-macro

v0.0.4

Published

Macro unplugin for Panda CSS

Downloads

8

Readme

@pandabox/unplugin-panda-macro

Make your styled-system disappear at build-time by inlining the results as class names.

Features

  • [x] Zero runtime
  • [x] Works with any panda.config
  • [x] You don't need to use the Panda CLI or postcss plugin
  • [x] Works with React/Solid
  • [x] Automatically remove unused CSS variables/keyframes

Supports

  • [x] css css({ ... }) / css.raw({ ... })
  • [x] cva const xxx = cva({ ... })
  • [x] recipes button({ ... })
  • [x] JSX styled factory styled.div({ ... }) / styled('div', { ... })
  • [x] any function or JSX pattern like box() / <Box />, stack() / <Stack /> etc

⚠️ Avoid anything dynamic as usual, if not more, with Panda CSS due to static analysis limitations.

Runtime conditions will NOT be transformed

You can even choose to inline as atomic or grouped class names.

From:

import { css } from '../styled-system/css'

export const App = () => {
  return (
    <>
      <div
        className={css({
          display: 'flex',
          flexDirection: 'column',
          fontWeight: 'semibold',
          color: 'green.300',
          textAlign: 'center',
          textStyle: '4xl',
        })}
      >
        <span>Hello from Panda</span>
      </div>
      <styled.div
        display="flex"
        flexDirection="column"
        fontWeight="semibold"
        color="green.300"
        textAlign="center"
        textStyle="4xl"
        onClick={() => console.log('hello')}
        unresolvable={something}
      >
        <span>Hello from Panda</span>
      </styled.div>
    </>
  )
}

To (atomic):

import { css } from '../styled-system/css'

export const App = () => {
  return (
    <>
      <div className={'d_flex flex_column font_semibold text_green.300 text_center textStyle_4xl'}>
        <span>Hello from Panda</span>
      </div>
      <div
        className="d_flex flex_column font_semibold text_green.300 text_center textStyle_4xl"
        onClick={() => console.log('hello')}
        unresolvable={something}
      >
        <span>Hello from Panda</span>
      </div>
    </>
  )
}

To (grouped):

import { css } from '../styled-system/css'

export const App = () => {
  return (
    <>
      <div className={'gTAnXW'}>
        <span>Hello from Panda</span>
      </div>
      <div className="gTAnXW" onClick={() => console.log('hello')} unresolvable={something}>
        <span>Hello from Panda</span>
      </div>
    </>
  )
}

Install

npm i @pandabox/unplugin-panda-macro

Plugin Options:

type PluginOptions = {
  /** @see https://panda-css.com/docs/references/config#cwd */
  cwd?: string
  /** @see https://panda-css.com/docs/references/cli#--config--c-1 */
  configPath?: string | undefined
  /**
   * @see https://www.npmjs.com/package/@rollup/pluginutils#include-and-exclude
   * @default `[/\.[cm]?[jt]sx?$/]`
   */
  include?: string | RegExp | (string | RegExp)[]
  /**
   * @see https://www.npmjs.com/package/@rollup/pluginutils#include-and-exclude
   * @default [/node_modules/]
   */
  exclude?: string | RegExp | (string | RegExp)[]
  /**
   * @example
   * ```ts
   * // `atomic`
   * const className = css({ display: "flex", flexDirection: "column", color: "red.300" })`
   * // -> `const className = 'd_flex flex_column text_red.300'`
   *
   * // `grouped`
   * const className = css({ display: "flex", flexDirection: "column", color: "red.300" })`
   * // -> `const className = 'hkogUJ'`
   * ```
   *
   * @default `'atomic'`
   */
  output?: 'atomic' | 'grouped'
  /**
   * Will remove unused CSS variables and keyframes from the generated CSS
   */
  optimizeCss?: boolean
  /**
   * Do not transform Panda recipes to `atomic` or `grouped` and instead keep their defaults BEM-like classes
   */
  keepRecipeClassNames?: boolean
  /**
   * Only transform macro imports
   * @example
   * ```ts
   * import { css } from '../styled-system/css' with { type: "macro" }
   *
   * const className = css({ display: "flex", flexDirection: "column", color: "red.300" })
   * // -> `const className = 'd_flex flex_column text_red.300'`
   * ```
   *
   */
  onlyMacroImports?: boolean
}

Then you can add this line import 'virtual:panda.css' somewhere in your app

You don't need to use Panda CSS postcss plugin and you don't need to import the styled-system/styles.css either

// vite.config.ts
import panda from '@pandabox/unplugin-panda-macro/vite'

export default defineConfig({
  plugins: [
    panda({
      /* options */
    }),
  ],
})

Example: playground/

// rollup.config.js
import panda from '@pandabox/unplugin-panda-macro/rollup'

export default {
  plugins: [
    panda({
      /* options */
    }),
  ],
}

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('@pandabox/unplugin-panda-macro/webpack')({
      /* options */
    }),
  ],
}

// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    [
      '@pandabox/unplugin-panda-macro/nuxt',
      {
        /* options */
      },
    ],
  ],
})

This module works for both Nuxt 2 and Nuxt Vite

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('@pandabox/unplugin-panda-macro/webpack')({
        /* options */
      }),
    ],
  },
}

// esbuild.config.js
import { build } from 'esbuild'
import panda from '@pandabox/unplugin-panda-macro/esbuild'

build({
  plugins: [panda()],
})

Made with

NPM version

Panda template for unplugin.