We are currently grappling with the challenge of effectively implementing tree shaking for CSS within Vue Single File Components using Webpack.
Within our package.json file, we have specified:
"sideEffects": ["*.css", "*.less","*.vue"]
, which appears to be successfully preventing unnecessary loading of Vue components. However, we are encountering the issue where every <style>
tag from the SFCs is still being loaded on the page.
The method by which we load our SFCs involves an NPM package listing numerous exports, such as:
export blah from 'blah.vue';
export blah2 from 'blah2.vue';
export blah3 from 'blah3.vue';
Even if our JavaScript only contains
import { blah3 } from 'a-npm-package';
, it includes styles from all three components. Given that we have a considerable number of Vue components, this results in a surplus of unused CSS cluttering the page.
How can we address this issue? Surely there must be a more efficient and dynamic approach to handling styles rather than indiscriminately injecting them all into the page, especially when only a fraction of them are actually utilized?
Thank you for any insights or guidance.