-
-
Notifications
You must be signed in to change notification settings - Fork 597
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
css-loader + tree-shaking + transpiled imports (babel) not working as it should. #769
Comments
@magnusriga please create minimum reproducible test repo with minimum webpack config |
@evilebottnawi I have now created a small test project. In the process, I discovered that the problem occurs when |
@magnusriga all |
What I expected: When adding sideEffects: ["*.css"] to What happened instead: When adding I have included a minimal working example above, to demonstrate the effect (https://github.com/magnusriga/css-loader). Just build once with |
I don't think this is a problem with babel, but some difference between babel has no effect. |
@magnusriga webpack treeshaking only works with ES6 module syntax, have you tried disabling the module transformation? Example:
|
@joselcc I have not tried that yet. I basically removed sideEffects in package.json and instead just imported all related css in each js component. |
here is an example of Webpack tree shaking working with babel and css loader |
Answer above with example, feel free to feedback |
@joselcc I've just lost a day on this issue (Webpack 4), so here's what worked for me, in case someone else stumbles on this (and his Webpack contains the ability to specify a glob in
|
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When compiling a bundle with Webpack and css-loader in development mode, all css files in component-style subfolders are included. When doing a production build however, only the top level CSS is included (CSS directly within src folder), while all other css (in various subfolders of src) are missing from final bundle.
I tried removing all conditional statements based on
isProduction
from the webpack config. It still did not work. So, I assumed it had to do with tree shaking somehow.Changing sideEffects in package.json did not work (it already had: ".css", ".scss").
By random chance I tried adding the following into babel-loader:
"plugins": ["@babel/plugin-transform-modules-commonjs"]
Suddenly it worked.
What is going on here?
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
See above.
The text was updated successfully, but these errors were encountered: