Closed jacobcarpenter closed 1 year ago
Hi!
Can you provide a small repo?
I tried a small one: https://github.com/vitejs/vite-plugin-react-swc/blob/emotion-plugin/playground/emotion-plugin/src/App.tsx#L6-L9, it works in dev and prod.
The build jumped from 174kb
to around 181kb
when I added the Theme provider.
Sure thing @ArnaudBarre! Here you go: https://github.com/jacobcarpenter/swc-plugin-error
There are two branches: main
and working-in-3.0.1
.
To see the error:
1) clone and checkout main
2) yarn
3) yarn build
then yarn preview
... you should see an empty page and the message ReferenceError: React is not defined
in the console
Contrast with yarn dev
which works.
To see that the error is new to 3.1.0
:
1) checkout working-in-3.0.1
2) yarn
(you must install the version rollback after switching branches)
3) yarn build
then yarn preview
... the page should work.
Fixed in v3.2!
Possibly related to #50
I have an app that uses theme-ui/core to enable an
sx
prop for css-in-js component styling; this requires configuring ajsxImportSource
.Theme UI delegates to Emotion for the actual css generation and injection. Emotion highly recommends configuring a plugin for some build-time optimizations to the generated css. I'm using the "official swc plugin"—which, sadly doesn't seem to be mentioned in the core babel-plugin docs anywhere.
Here is my complete
vite.config.js
:With
@vitejs/plugin-react-swc
@3.0.1
, thebuild
output looked like the following and resulted in a functional react app:After upgrading to
3.1.0
without modifying the config, thebuild
output now looks like:Note some pretty dramatic differences in "# of modules transformed" and the bundle size for
dist/assets/index
.The built site, when run under
yarn preview
produces a script error:ReferenceError: React is not defined
.If I comment out
plugins: [['@swc/plugin-emotion', {}]]
, the build output stats are closer to the3.0.1
version, and it produces a functional build: