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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@emotion-extract/vite

v1.13.4

Published

Use Emotion CSS with the performance of handwritten stylesheets.

Readme

@emotion-extract/vite 👩‍🎤

This Vite plugin brings Emotion's CSS rules to server-rendered projects using React, Preact, Svelte, Vue, SvelteKit, Astro, Remix, or basically any Vite-based project.

Why Emotion?

Emotion lets you colocate CSS rules with your JSX instead of having them in a separate file. You might find it easier to write and maintain your styles using vanilla CSS properties!

@emotion-extract/vite takes Emotion to the next-level! Instead of generating stylesheets in the browser everytime your components render and re-render, it makes them available ahead of time, even before the browser has run any code. This greatly improves rendering performance, and improves Lighthouse metrics. Additionally, it is compatible with server components, which don't send any code to the browser at all.

It works by reading your components' source code, and creating stylesheets from it during build-time. This approach is often called "macros" or "runes". This integration offers two macros - css, and injectGlobal. The css template tag processes CSS properties and compiles them into a scoped class name, which you can add to your HTML elements. The injectGlobal template tag lets you add global styles to the current page.

Emotion is also a great choice to add styles to React, Preact, or Solid components, which don't have an out-of-the-box styling solution.

Installation

First, install the @emotion-extract/vite package using your package manager. If you're using npm or aren't sure, run this in the terminal:

npm install --save-dev @emotion-extract/vite

Notice how we added the --save-dev flag. This is because Emotion Extract runs entirely during build time; none of its code runs in the browser or in the SSR app. If you are migrating from @emotion/css or @emotion/react, you can remove those packages from your dependency list.

Next, add the plugin to your vite.config.* file using the plugins array:

// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
+ import emotion from '@emotion-extract/vite';

// https://vite.dev/config/
export default defineConfig({
  // ...
  plugins: [react(), emotion()],
  // ...             ^^^^^^^^^
})

To enable autocomplete and type-safety hints, add an import statement for @emotion-extract/vite/env:

// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
+ import '@emotion-extract/vite/env';

// https://vite.dev/config/
export default defineConfig({
  // ...
})

If this step is skipped, you might see the following error message in your IDE:

Cannot find module 'emotion:extract' or its corresponding type declarations.ts(2307)

Usage

Once the integration is installed and added to the configuration file, you can import the css and injectGlobal macros from the "emotion:extract" module inside your components.

// src/components/react.tsx
import { css, injectGlobal } from "emotion:extract"

injectGlobal`
  body {
    margin: 0;
    padding: 0;
  }
`

export default function () => (
  <div
    className={css`
      background-color: hotpink;
      &:hover {
        color: white;
      }
    `}
  >
    This has a hotpink background.
  </div>
)

Limitations

Since the integration acts only during build-time, it cannot process dynamic styles. For example, this will not work:

import { css } from "emotion:extract"
const margin = "1rem"
const className = css`margin: ${margin};`
const element = <div className={className} />

Instead use CSS variables for values that may change:

import { css } from "emotion:extract"
const margin = "1rem"
const className = css`margin: var(--margin);`
const element = <div style={{ "--margin": margin }} className={className} />

Troubleshooting

For help, check out the Discussions tab on the GitHub repo.

Contributing

This package is maintained by lilnasy. The integration code is located at packages/emotion-extract/vite.ts. You're welcome to contribute by opening a PR or submitting an issue!

Changelog

See CHANGELOG.md for a history of changes to this integration.