webpack 4 tree-shaking style sideEffects: Fix
See original GitHub issueWhat problem does this feature solve?
Essentially it’s an instruction to the vue-loader to import and use the style from the same file (recursively). The resulting value of style is {}, but it **tricks webpack into thinking the style in this file is not a side-effect.
What does the proposed API look like?
– file: Palette.vue —
<script>
import style from './Palette.vue?vue&type=style&index=0&module=true&lang=stylus&'
export default {
style,
...
}
</script>
<style scoped lang="stylus">
...
</style>
It could be possible to append a similar import to the front of the script section automatically in the vue-loader, thereby making the style mandatory .
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Tree Shaking - webpack
Clarifying tree shaking and sideEffects ... The sideEffects and usedExports (more known as tree shaking) optimizations are two different things. sideEffects is ...
Read more >Tree shaking and code splitting in webpack - LogRocket Blog
Here, we'll explain tree shaking and code splitting in webpack and discuss how to combine them for the most optimal bundle possible.
Read more >How to Fully Optimize Webpack 4 Tree Shaking | by Craig Miller
A file with side effects should NOT be tree-shaken, as this will damage the application as a whole. The designers of Webpack, ...
Read more >How I fixed webpack tree shaking in 3 easy steps
Tree shaking is an important step in Webpack bundling to get rid of unused stuff. This should help describe how to easily get...
Read more >Tree Shaking - SurviveJS
For tools like webpack to allow tree shake npm packages, you should generate a build that has transpiled everything else except the ES2015...
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 FreeTop 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
Top GitHub Comments
https://github.com/vuejs/vue-loader/issues/1435#issuecomment-869074949
It is the same issue reported in: https://github.com/vuejs/vue-loader/issues/1435 https://github.com/vuejs/vue-loader/issues/1295 And documented at the bottom of this page: https://vue-loader.vuejs.org/guide/#manual-setup
General: The problem is if you are writing libraries, and exposing SFCs the CSS is not included in the resulting tree-shaken result. Despite what the docs above say CSS included in a .vue file SHOULD NOT be side effects.
It can be “fixed”
but this results i turning off tree shaking for the larger part of the library
Another solution is to import each .vue file individually, instead of exporting them as named exports. But this makes using the library more difficult and clunky.
The PR I posted isn’t ideal. But it does demonstrate one way to register the styles as mandatory only when their associated VUE files get used.
If there is a better way to attach the <style>s in a vue file to the export default script object then it would be great. (maybe in a way that is similar to the templates?)