Production build returns multiple styles
See original GitHub issueCurrent behavior:
I use Emotion with “@emotion/babel-preset-css-prop”. In production environment Emotion creates multiple style tags. This is desired for the dev environment, but not for production.
To reproduce:
- For testing purposes I have created a simple React component.
class Welcome extends React.Component {
render() {
return (
<div css={{ backgroundColor: 'red' }}>
<div css={{ color: 'yellow'}}>Yellow div</div>
);
}
}
- In the .babelrc within the production env, I have added within the presets at the first place the @emotion/babel-preset-css-prop.
"production": {
"presets": [
["@emotion/babel-preset-css-prop"],
[
"@babel/preset-env",
{
"useBuiltIns": false,
"targets": {
"browsers": ["last 2 versions"]
},
"debug": false
}
],
["@babel/preset-typescript"],
"@babel/preset-react"
],
"plugins": [ .... ]
- I get one global stylesheet file, but each css styling gets rendered in a new style tag within the html head. This is on purpose for the dev build, but not for production mode.
Given the component above my head looks as following:
<style data-emotion="css-global"></style>
<style data-emotion-css="f5yfbg">.css-f5yfbg{background-color:red;}</style>
<style data-emotion-css="fsfbn2">.css-fsfbn2{color:yellow;}</style>
I read all issues regarding to Emotion, but I couldn’t find something similiar.
Expected behavior:
Emotion should render one single stylesheet file.
Environment information:
react
version: 16.8.6emotion
version: [ “@emotion/core”: “^10.0.10”, “@emotion/styled”: “^10.0.4”, “@emotion/babel-preset-css-prop”: “^10.0.9” ]
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:12 (4 by maintainers)
Top Results From Across the Web
React: Production build looks different from development build
I have a React/Django app that's behaving differently when built for production that it does when run on the development ...
Read more >Angular workspace configuration
Angular CLI comes with two build configurations: production and development . ... See more in the Styles and scripts configuration section.
Read more >Organizing your CSS - Learn web development | MDN
Break large stylesheets into multiple smaller ones ... In cases where you have very different styles for distinct parts of the site, you...
Read more >Strict Mode - React
Strict mode checks are run in development mode only; they do not impact the production build. You can enable strict mode for any...
Read more >E CSS in JS | Client-Side Web Development
But almost all of them will either generate an inline style to inject into an element, or will produce their own injected stylesheet...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I really want create a seperate css file, don’t like css in html. 😦 it can make site slow down (1% i think XD)…
@baldurh baldurh How did you get it working ? Could you append a codesnippe or point me to the right direction ?