Skip to content
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

Mark CSS files as side effects #68

Closed
kossidts opened this issue Apr 4, 2024 · 4 comments · Fixed by #71
Closed

Mark CSS files as side effects #68

kossidts opened this issue Apr 4, 2024 · 4 comments · Fixed by #71

Comments

@kossidts
Copy link
Contributor

kossidts commented Apr 4, 2024

When setting "sideEffects": false in the package.json file of this package, it leads to an issue where the CSS file is excluded from the resulting bundle, essentially shaken out from the tree. This is a known issue that affects many packages.

As described in the webpack documentation on Tree Shaking, I believe a better solution might be to specify specific files that should be treated as side effects e.g. "sideEffects": ["*.css"] ensuring that the CSS file is included in the bundle and not eliminated during the tree shaking process.

I have created a PR #69 fixing this issue.

@g-hor
Copy link

g-hor commented Apr 4, 2024

Thanks for opening this issue! I was about to open one of my own when I realized none of the stylesheets were applying. It took me a while to figure out that they were getting shaken out. Cheers for your fix

@Wondermarin
Copy link
Owner

I will merge your PR and close the issue as soon as possible (within the next couple of days). Apologies for any inconvenience this may cause. Thank you for your patience and contribution.

@g-hor
Copy link

g-hor commented Apr 5, 2024

In case anyone else runs into this same issue before it's fixed, one workaround that I found to work for me was to import the stylesheet via require() rather than import():

// This gets tree-shaken from build >> no styles applied
import 'react-color-palette/css';

// ✅ This does not get tree-shaken from build >> styles applied
require('react-color-palette/css');

Wondermarin pushed a commit that referenced this issue Apr 10, 2024
@Wondermarin Wondermarin linked a pull request Apr 10, 2024 that will close this issue
@Wondermarin
Copy link
Owner

Wondermarin commented Apr 10, 2024

Should be fixed in v7.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants