CSS files cannot be treeshaken with side effects
See original GitHub issueDescribe the bug
vue-cli(webpack) VS vite
Reproduction
https://github.com/BuptStEve/vite-css-treeshake
-
npm start
to run vue-cli -
npm run vite
to run vite -
npm run build
to run vue-cli -
npm run vite:build
to run vite
System Info
System:
OS: macOS 11.4
CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Memory: 2.44 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.1 - ~/.nvm/versions/node/v14.17.1/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.13 - ~/.nvm/versions/node/v14.17.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 92.0.4515.107
Safari: 14.1.1
npmPackages:
vite: ^2.4.3 => 2.4.3
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Tree Shaking - webpack
css : No export is used, but flagged with sideEffects -> include it. In this case only 4 modules are included into the...
Read more >Webpack not acting on sideEffects for css files - Stack Overflow
This will be because treeshaking sees the CSS file as not having any side effects. The recommended way of dealing with this is...
Read more >Tree shaking and code splitting in webpack - LogRocket Blog
Modules that are side effects cannot be tree shaken because they don't have imports and exports. But, code doesn't have to be a...
Read more >Features | Vite
Vite will detect such bare module imports in all served source files and perform ... rather import all the modules directly (e.g. relying...
Read more >Tree-Shaking Problems with Component Libraries - Medium
Add a "sideEffects" property to your project's package.json file. ... modules being bundled into a single file, which cannot be tree-shaken.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, this feature is useful for UI library to auto import component’s own style by default. And when you build app, it also helps treeshake unused ones(with style).
@mayank99 I don’t think there’s a workaround today, but I agree there should be a way around this, like the
sideEffects
field discussed above. I’ll put this on the team board to confirm if this is the design we want, or if there’s an alternate API design.