A Babel plugin for Emotion, the CSS-in-JS library, that enables automatic JSX pragma, source maps, and minification of styles. The current stable version is 11.14.0 (last updated late 2024). It is released regularly alongside the main Emotion monorepo. Unlike the older `babel-plugin-emotion` (v10), this package is scoped under `@emotion` and requires Babel 7+. Key differentiator: it is the recommended plugin for Emotion v11+, providing optimizations like label generation and dead code elimination.
npm install babel-plugin-emotionVerified import paths — ran on the pinned version, not inferred.
Shows Babel config with @emotion plugin and basic styled component using css prop.
Replace all references from 'babel-plugin-emotion' to '@emotion/babel-plugin'.
Consult the new options documentation. Common options like `sourceMap` and `autoLabel` are still supported but need to be passed differently.
Update to Babel 7 or later. The package `@emotion/babel-plugin` does not support Babel 6.
Use `autoLabel: true` or `autoLabel: 'dev-only'` instead of `labelFormat`.
Run `npm install --save-dev @emotion/babel-plugin` and ensure config uses the scoped name.
Install `@babel/plugin-proposal-class-properties` or use the `@babel/preset-env` preset.
Set `runtime: 'automatic'` in `@babel/preset-react` options.
Either add `import React from 'react'` in every file or use the automatic runtime with `@babel/preset-react`.