UNPKG

1.45 kBJavaScriptView Raw
1import jsx from '@babel/plugin-transform-react-jsx'
2import pragmatic from '@emotion/babel-plugin-jsx-pragmatic'
3import emotion from '@emotion/babel-plugin'
4
5let pragmaName = '___EmotionJSX'
6
7// pull out the emotion options and pass everything else to the jsx transformer
8// this means if @babel/plugin-transform-react-jsx adds more options, it'll just work
9// and if @emotion/babel-plugin adds more options we can add them since this lives in
10// the same repo as @emotion/babel-plugin
11
12export default (
13 api,
14 { pragma, sourceMap, autoLabel, labelFormat, importMap, ...options } = {}
15) => {
16 if (options.runtime) {
17 throw new Error(
18 'The `runtime` option has been removed. If you want to configure `runtime: "automatic"`, replace `@emotion/babel-preset-css-prop` with `@babel/preset-react` and `@emotion/babel-plugin`. You can find out how to configure things properly here: https://emotion.sh/docs/css-prop#babel-preset'
19 )
20 }
21
22 return {
23 plugins: [
24 [
25 pragmatic,
26 {
27 export: 'jsx',
28 module: '@emotion/react',
29 import: pragmaName
30 }
31 ],
32 [
33 jsx,
34 {
35 pragma: pragmaName,
36 pragmaFrag: 'React.Fragment',
37 ...options
38 }
39 ],
40 [
41 emotion,
42 {
43 sourceMap,
44 autoLabel,
45 labelFormat,
46 cssPropOptimization: true,
47 importMap
48 }
49 ]
50 ]
51 }
52}