Skip to content

Commit

Permalink
feat(emotion): add importMap to the babel plugin (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanbanov committed Jul 8, 2021
1 parent 46145a6 commit 657f7fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/babel-preset-emotion-css-prop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default (
sourceMap,
autoLabel,
labelFormat,
importMap,
instances = [],
...options
} = {},
Expand All @@ -40,6 +41,7 @@ export default (
sourceMap,
autoLabel,
labelFormat,
importMap,
instances: ['@xstyled/emotion', ...instances],
cssPropOptimization: true,
},
Expand Down
19 changes: 8 additions & 11 deletions website/pages/docs/getting-started/migrate-from-emotion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -221,30 +221,27 @@ To avoid the `/** @jsx jsx */` you can use `@xstyled/babel-preset-emotion-css-pr

You may want to use [Emotion Babel plugin](https://emotion.sh/docs/babel) for minification of styles, dead code elimination, components as selectors, and a nicer debugging experience.

You have to specify xstyled inside the `importMap`:

**.babelrc**

```js
{
...,
"plugins": [
"presets": [
[
"@emotion/babel-plugin",
"@xstyled/babel-preset-emotion-css-prop",
{
"importMap": {
"@xstyled/emotion": {
"default": {
"canonicalImport": ["@emotion/styled", "default"]
}
}
}
// @emotion/babel-plugin options
// https://emotion.sh/docs/@emotion/babel-plugin
}
]
]
}
```

Note: `importMap` has some known issues coming from Emotion side
- [Emotion not compatible with styled.box](https://github.com/gregberge/xstyled/issues/286)
- [CSS prop doesnt have access to the theme](https://github.com/gregberge/xstyled/issues/285)

### Difference in `css` prop usage

`css` prop with `@xstyled/emotion` is slightly different from `css` prop with `@emotion/react`.
Expand Down

0 comments on commit 657f7fe

Please sign in to comment.