question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS files cannot be treeshaken with side effects

See original GitHub issue

Describe the bug

image

vue-cli(webpack) VS vite

image

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
BuptStEvecommented, Mar 16, 2022

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).

3reactions
bluwycommented, Oct 3, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found