You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
react-scripts@next drops css import in production build #5140
Note that any imported file is subject to tree shaking. This means if you use something like css-loader in your project and import a CSS file, it needs to be added to the side effect list so it will not be unintentionally dropped in production mode:
Therefore react-octagon's package.json needs to instead use something like:
"sideEffects": ["*.css"],
Reacted by Aidar Ibatullin, Ian Sutherland and Joe Haddad
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*ascssfrom'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 sideEffects: [ <css glob > ] to make webpack hold onto any css file. this does not work for the aforementioned example, but IMHO matches the language used in the webpack docs.
having the whole thing work by declaring css sideEffects inreact-octagon seems off. from react-octagon's perspective, a css file doesn't fit the definition of a sideEffect--it's a logicless asset.
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 sideEffects entry in package.json. And that API currently requires packages to list all files including CSS, since webpack doesn't special-case particular types (and doesn't offer a way for its loaders to do so either).
As such at least in the feature's current implementation, omitting CSS file entries from the sideEffects property is a bug.
However I agree the sideEffects feature should be improved - discussion in webpack/webpack#6571.
Activity
edmorley commentedon Sep 27, 2018
Hi @cdaringe :-)
The
react-octagonpackage has setsideEffects: falsein theirpackage.json:https://github.com/Tripwire/octagon/blob/v15.1.2/package.json#L98
As such when
modeis'production'webpack 4's improved tree shaking drops the import by design.From the webpack tree shaking docs:
Therefore react-octagon's
package.jsonneeds to instead use something like:01dr commentedon Sep 27, 2018
This is it. I tried this case with a other library, and everything works correctly
cdaringe commentedon Sep 28, 2018
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.
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
sideEffects: [ <css glob > ]to make webpack hold onto any css file. this does not work for the aforementioned example, but IMHO matches the language used in the webpack docs.having the whole thing work by declaring css
sideEffectsinreact-octagonseems off. fromreact-octagon's perspective, a css file doesn't fit the definition of a sideEffect--it's a logicless asset.what perspective am i missing here? maybe this conversation is better suited for the webpack repo :)
edmorley commentedon Sep 28, 2018
@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
sideEffectsentry inpackage.json. And that API currently requires packages to list all files including CSS, since webpack doesn't special-case particular types (and doesn't offer a way for its loaders to do so either).As such at least in the feature's current implementation, omitting CSS file entries from the
sideEffectsproperty is a bug.However I agree the sideEffects feature should be improved - discussion in webpack/webpack#6571.