-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-scripts@next drops css import in production build #5140
Comments
Hi @cdaringe :-) The As such when From the webpack tree shaking docs:
Therefore react-octagon's "sideEffects": [
"*.css"
], |
This is it. I tried this case with a other library, and everything works correctly |
cool, thanks all. it was because of side effects indeed, but just to clarify, i don't think the prescribed solution is the ideal solution. the root cause is really that i simply didn't use that import. // works.
import * as css from 'react-octagon/lib/styles/semantic.css'
console.log(css) // can't shake me now, i'm used! thus, because my code didn't use the css, it was shaken. i would think in my CRA project (not my dependencies) i would declare having the whole thing work by declaring css what perspective am i missing here? maybe this conversation is better suited for the webpack repo :) |
@cdaringe it's valid to have imports that are not assigned to anything. The issue here is that webpack 4 created a new way for packages to declare "none/some/all of the files in this package have any side-effects by importing alone, so it's safe to drop them as an optimization", via the optional As such at least in the feature's current implementation, omitting CSS file entries from the However I agree the sideEffects feature should be improved - discussion in webpack/webpack#6571. |
Is this a bug report?
yes
Did you try recovering your dependencies?
yes.
Which terms did you search for in User Guide?
n/a
Environment
Steps to Reproduce
(Write your steps here:)
npx create-react-app@next
, the other adds a component lib & style sheetyarn start
. observe a styles applied. kill the processyarn build
. serve the production build. observe missing styles.originally discovered here
Expected Behavior
import
ed stylesheet should be included in bundleActual Behavior
import
ed stylesheet is missingmore specfically, here, a css file is imported as shown below:
this dependency shows up in dev mode in the dev server, but no such CSS is generated into the build dir.
interestingly, importing the desired css file from within another CSS file produces expected results. see @youngbob's remark here.
Reproducible Demo
instructions listed above.
The text was updated successfully, but these errors were encountered: