Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component included in production build when using named imports even though it's not included #88

Closed
adriaanmeuris opened this issue Mar 10, 2023 · 1 comment
Labels
question Further information is requested

Comments

@adriaanmeuris
Copy link

I'n using relativeCSSInjection to build a UI library with 2 components Comp1 and Comp2. This works fine and generates different entries for consuming the library:

  • lib.js: contains all components with embedded css
  • Comp1.js: contains component 1 with embedded css
  • Comp2.js: contains component 2 with embedded css

When consuming this library, I'd like to use named imports like this:

import { Comp1 } from 'lib.js'; // Component 2 is included in bundle

Even though I'm not using Comp2, it will be included in the bundle:
Screenshot 2023-03-10 at 10 43 59

When consuming this library with a direct import like this:

import Comp1 from 'Comp1.js'; // Component 2 is not included in bundle = desired behaviour)

In this case, Comp2 won't be included in the bundle (= desired behaviour):
Screenshot 2023-03-10 at 10 45 39

You can find a reproduction repository here: https://github.com/adriaanmeuris/css-injected-by-js-issue

I did some research and I think this might be caused by vitejs/vite#4389.

Can you confirm this is the cause of this behaviour, and if not: how can I use named imports without having other components being included in the final bundle?

@marco-prontera
Copy link
Owner

Hi @adriaanmeuris I tried your repository with and without this plugin but the behaviour seems is the same, this plugin only takes the CSS and add it through the JS, the relativeCSSInjection option is experimental because we are not sure if it's usable in every case.
The behaviour you have is a little bit strange because you are using only one component at time so the three shaking must "delete" the unused export, but this is not related to that plugin I'm sorry, if you find some problem with this plugin please open an issue, I will close this issue for the moment

@marco-prontera marco-prontera added the question Further information is requested label May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants