MCPcopy Index your code
hub / github.com/arlyon/stailwc

github.com/arlyon/stailwc @0.17.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.17.0 ↗ · + Follow
412 symbols 793 edges 256 files 15 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

stailwc (speedy tailwind compiler)

This is an experimental SWC transpiler to bring compile time tailwind macros to SWC (and nextjs) a-la twin macro. The goal is to give the same great compile-time ergonomics and flexibility while performing considerably better than babel-based alternatives. Supports both emotion and styled-components for CSS-in-JS, and many build systems such as SWC, nextjs, Vite, etc.

Compatibility Chart

We are currently testing against the following versions. Other versions outside these may still work, however.

stailwc NextJS Emotion Styled Components swc Vite
latest 13.4.3 11.10.5 5.3.6 1.3.24 4.1.0

Feature Chart

Feature Emotion Styled Components
tw jsx attribute
tw template tag
tw component syntax
tw component extension syntax
Global styles
Plugin parameter suggestions

Getting started

> npm add -D stailwc
> yarn add -D stailwc
> pnpm add -D stailwc

To get started with NextJS, place the following in your next.config.js. For other framworks / tools, please see the examples.

next.config.js

const stailwc = require("stailwc/install");

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  experimental: {
    swcPlugins: [
      stailwc({
        engine: "emotion", // or "styled-components"
      }),
    ],
  },
  compiler: {
    emotion: true,
    // or
    styledComponents: true,
  },
};

module.exports = nextConfig;

Optionally, you can also include the tailwind normalizer + forms plugin by including the <TailwindStyle /> component. Please see the relevant examples.

_document.tsx

import { TailwindStyle } from "stailwc";

export default function App({ Component, pageProps }) {
  return (
    <>
      <TailwindStyle />
      <Component {...pageProps} />
    </>
  );
}

Types

There is one step you need to take to get types working. You need to add stailwc.d.ts to the root of your source folder.

Usage

The tw tag

You can interact with stailwc in two ways. The first is through the tw JSW attribute, and the second is via the tw template tag.

import { useState } from "react";

export const ColorButton = () => {
  const [clicked, setClicked] = useState(0);
  return (
    <button
      tw="p-1 m-4 text-green bg-white hover:(bg-gray text-yellow md:text-red) border-3"
      css={clicked % 2 == 0 ? tw`border-green` : tw`border-blue`}
      onClick={() => setClicked(clicked + 1)}
    >
      Clicked {clicked} times
    </button>
  );
};

Component syntax

You can also create styled components using the tw template tag. This will automatically create the correct syntax for both emotion and styled-components.

export const StyledButton = tw.button`p-1 m-4 text-green bg-white hover:(bg-gray text-yellow md:text-red) border-3`;
export const ShadowButton = tw(StyledButton)`shadow-lg`;

Examples

There are examples available for both emotion and styled-components. You can run them by cloning the repo and running yarn followed by yarn dev in the example directory. You will need to stailwc first.

Extension points exported contracts — how you extend this code

DOMAttributes (Interface)
(no doc)
stailwc.d.ts
DOMAttributes (Interface)
(no doc)
examples/vite/src/stailwc.d.ts
IntrinsicAttributes (Interface)
(no doc)
stailwc.d.ts
IntrinsicAttributes (Interface)
(no doc)
examples/vite/src/stailwc.d.ts

Core symbols most depended-on inside this repo

named_literal
called by 69
crates/swc-utils/src/lib.rs
to_lit
called by 66
crates/swc-utils/src/lib.rs
push
called by 17
src/depth_stack.rs
report
called by 8
src/lib.rs
span
called by 7
crates/tailwind-parse/src/expression.rs
merge_literals
called by 6
crates/swc-utils/src/lib.rs
simple_lookup
called by 4
crates/tailwind-parse/src/eval/plugin.rs
as_str
called by 4
crates/tailwind-parse/src/eval/util.rs

Shape

Function 303
Enum 46
Method 43
Class 16
Interface 4

Languages

Rust97%
TypeScript3%

Modules by API surface

crates/tailwind-parse/src/eval/plugin.rs42 symbols
crates/tailwind-parse/src/plugin.rs34 symbols
crates/tailwind-parse/src/literal.rs16 symbols
src/lib.rs13 symbols
crates/test-generator/src/lib.rs12 symbols
crates/swc-utils/src/lib.rs11 symbols
src/depth_stack.rs9 symbols
crates/tailwind-parse/src/lib.rs9 symbols
crates/tailwind-parse/src/eval/util.rs6 symbols
crates/tailwind-parse-macro/src/lib.rs6 symbols
crates/tailwind-parse/src/expression.rs5 symbols
crates/tailwind-config/src/lib.rs5 symbols

For agents

$ claude mcp add stailwc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact