-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
fix: add styles to sideEffects #408
fix: add styles to sideEffects #408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
@andreafalzetti Hi! Thank you very much for PR and good explanation why you wanna introduce this changes. To be honest I'm very surprised that webpack tree-shakes the styles when you explicit defined import for them (as I understand). I currently read the docs for webpack and here we have:
So I guess that css doesn't produce an export and due to this webpack drop it. Good to know fo the future 😅 Also as I understand, the another workaround is making something like that: import '@asyncapi/react-component/styles/default.css';
import styles from '@asyncapi/react-component/styles/default.css';
console.log(styles); I also found another possible solution -> https://linguinecode.com/post/reduce-css-file-size-webpack-tree-shaking Do you use the custom webpack or webpack from cli like I will accept changes and merge it, but I'm very interesting if you can change the config for tree-shaking of particular module in your webpack.If you use predefined webpack, please let me know and I will merge it immediatelly. And sorry for problems 😅 Also please change the title of issue to the |
cc96e5c
to
957171a
Compare
Thanks for the quick reply! :) No problem at all, actually thanks a lot for building and publishing this package open source! First, I have updated the PR title and also commit message using the
That's right! After an investigation, I arrived at the same conclusion. The webpack docs that you mentioned seem correct and coherent to the behaviour that I have observed. The workaround of We have a custom webpack config, and Btw - not relevant to the discussion but.. Did you see the new feature from GitHub? Codespaces. I was able to raise this PR without having to clone/install anything on my machine, I did eveything from the browser, including git commits 😍 |
package.json
Outdated
"sideEffects": [ | ||
"./style/default.css", | ||
"./style/default.min.css" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreafalzetti Thanks for your comment. I heard about that but I didn't use yet, but my friend used and said that its great! Sorry, but I was in Friday off.
Before merge - it should be moved to the https://github.com/asyncapi/asyncapi-react/blob/master/library/package.json place (package.json of component) - here is a package.json where we have shared dependencies across project (we use the lerna for multirepo).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, good catch! Moved. Yon can review this in commit 60117f0
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
1 similar comment
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@andreafalzetti New version |
🎉 This PR is included in version 1.0.0-next.16 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Changes proposed in this pull request:
styles/*
excluded from webpack tree shaking usingsideEffects
inpackage.json
Related issue(s)
When imported the styles should cause side effects, but because the current release (I am using
1.0.0-next.15
) has"sideEffects": false,
inpackage.json
, webpack tree shakes theimport '@asyncapi/react-component/styles/default.css';
at build time.A workaround for us it's using
require
instead ofimport
just for this specific file but I rather fix the root issue than mixing require/import.I have tested locally and works as expected. I am open to different approaches if you thought of one, but according to webpack docs,
sideEffects
should be used exactly for this situation, let me know your thoughts!