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

Some problems with cssCodeSplit and Library Mode #8057

Closed
4 tasks done
Dunqing opened this issue May 7, 2022 · 6 comments · Fixed by #14945
Closed
4 tasks done

Some problems with cssCodeSplit and Library Mode #8057

Dunqing opened this issue May 7, 2022 · 6 comments · Fixed by #14945

Comments

@Dunqing
Copy link
Contributor

Dunqing commented May 7, 2022

Clear and concise description of the problem

I enabled preserveModules and cssCodeSplit in library mode.
But css files don't follow the preserveModules rule, use the original module name as the file name.

related code:

const fileHandle = this.emitFile({
name: chunk.name + '.css',
type: 'asset',
source: chunkCSS

Suggested solution

I want to use the original module name as the file name as required by preserveModules when cssCodeSplit is enabled.

Alternative

No response

Additional context

No response

Validations

@gburning
Copy link

Did you find a solution to this? I'd like to find a way to export my original modules alongside the concatenated style sheet.

@receter
Copy link

receter commented Aug 12, 2023

Instead of using preserveModules you can turn every file into an entry point. Like suggested in the Rollup docs:

If you want to convert a set of files to another format while maintaining the file structure and export signatures, the recommended way—instead of using output.preserveModules that may tree-shake exports as well as emit virtual files created by plugins—is to turn every file into an entry point. You can do so dynamically e.g. via the glob package:

I recently wrote a blog post including this topic: https://dev.to/receter/how-to-create-a-react-component-library-using-vites-library-mode-4lma

@emosheeep Your plugin works great for me, first I tried using preserveModules but this solution works even better and I also have more granular control. Maybe you could include this (better) alternative to using preserveModules in the docs? I can create a pull request if you want.

@emosheeep
Copy link
Contributor

emosheeep commented Aug 13, 2023

@receter I just read your blog, and I got you. Did you mean what need to be added to the docs is that you quoted above from Rollup's docs? I think it's ok, may be it can be added to "QA" or "Recipes of creating component library" section, and titled it properly. I’ll be appreciated it if you have time to work for this, because I'm just exhausted with my current job which is working my last nerve.

@Dunqing
Copy link
Contributor Author

Dunqing commented Aug 13, 2023

Instead of using preserveModules you can turn every file into an entry point. Like suggested in the Rollup docs:

If you want to convert a set of files to another format while maintaining the file structure and export signatures, the recommended way—instead of using output.preserveModules that may tree-shake exports as well as emit virtual files created by plugins—is to turn every file into an entry point. You can do so dynamically e.g. via the glob package:

I recently wrote a blog post including this topic: https://dev.to/receter/how-to-create-a-react-component-library-using-vites-library-mode-4lma

@emosheeep Your plugin works great for me, first I tried using preserveModules but this solution works even better and I also have more granular control. Maybe you could include this (better) alternative to using preserveModules in the docs? I can create a pull request if you want.

That's great. You inspired me, We can create a plugin that focuses on the lib mode, and it can follow preserveModules rules.

@victorpavlenko
Copy link

@receter Its work just perfect! Thanks a lot.
I just have a question regarding generate .cjs together with .es
As I know rollupOptions doesn't support arrays
Perhaps you have some ideas?

@receter
Copy link

receter commented Aug 27, 2023

@receter Its work just perfect! Thanks a lot. I just have a question regarding generate .cjs together with .es As I know rollupOptions doesn't support arrays Perhaps you have some ideas?

You could build .cjs in a separate build step.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants