-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unexpected (CSS) import removal with glob pattern in sideEffects array #1370
Comments
Thanks for the detailed bug report. I can confirm the problem. I don't think that's the case. It looks like the |
We've had Remix users reporting this issue when re-exporting components with CSS side-effects (via regular CSS, CSS Modules and Vanilla Extract): remix-run/remix#5270 |
I was able to work around this issue by replacing -export * from "./example";
+export { foo, bar } from "./example"; |
esbuild is an alternative to Webpack for TypeScript builds in local dev (https://docs.sourcegraph.com/dev/background-information/web/build#esbuild). The latest release of esbuild fixes an issue (evanw/esbuild#1370) that prevented us from using treeshaking. With esbuild 0.17.7, we can use treeshaking, which means smaller bundle sizes.
esbuild is an alternative to Webpack for TypeScript builds in local dev (https://docs.sourcegraph.com/dev/background-information/web/build#esbuild). The latest release of esbuild fixes an issue (evanw/esbuild#1370) that prevented us from using treeshaking. With esbuild 0.17.7, we can use treeshaking, which means smaller bundle sizes. ## Test plan n/a (dev only) ## App preview: - [Web](https://sg-web-sqs-upgrade-esbuild-treeshaking.onrender.com/search) Check out the [client app preview documentation](https://docs.sourcegraph.com/dev/how-to/client_pr_previews) to learn more.
Repro: https://github.com/jgoz/esbuild-side-effect-glob-issue
Some component libraries are built using global (non-module) CSS where each component imports a
.css
file as a side-effect import. A component module itself might be otherwise side-effect-free and rightfully subject to DCE, but its CSS import(s) should be included in the CSS bundle if and only if the component is included in the JS bundle.When using Webpack with
css-loader
, this behavior can be achieved by specifying"sideEffects": ["*.css"]
, which essentially indicates that for any module importing a.css
file, that import will be preserved since it is side-effect-having.In esbuild, however, specifying
sideEffects
per the above may result in those CSS imports being eliminated if the importing JS module has been re-exported through a dependency graph that has been determined to be side-effect-free.This can be observed in the repro repository where the root exports of the
a
package are determined to be side-effect-free, since they do not match any pattern in thesideEffects
array, which results ina.css
being stripped from the CSS output file even though the importing JS is included in the JS output file.Workarounds:
sideEffects
, which is tedioustreeShaking: 'ignore-annotations'
This is probably related to #1184 and its fix in e79a747.
I've also pasted the repro as a test case below.
Test case
Expected snapshot
Actual snapshot
The text was updated successfully, but these errors were encountered: