We are trying to figure out the correct way of handling tree shaking for CSS in Vue Single File Components with Webpack.
In package.json, I have: "sideEffects": ["*.css", "*.less","*.vue" ]
, this seems to be working properly for stopping Vue components from loading when they shouldn't be. However, every single <style>
tag from the SFCs is been loaded on the page.
How we are loading our SFC is from a NPM package that list a bunch of exports, like
export blah from 'blah.vue';
export blah2 from 'blah2.vue';
export blah3 from 'blah3.vue';
Even if in our JavaScript I have just import { blah3 } from 'a-npm-package';
it is including the styles from all three. Since we have a quite a few Vue components this is leading to a lot of unused CSS being added to the page.
How can we prevent this? There has to be a better more dynamic way of handling styles rather than just dumping them all into the page even if only 1/10th of them is being used?
Thanks