Incorporating a custom NPM CSS library into an Angular component library

I’m working on an Angular component library that I plan to publish as an NPM package. I’ve got a custom CSS library that I created and published on NPM. Now I’m wondering about the best approach to include this CSS in my component library.

Some developers suggest adding the CSS globally to the workspace instead of bundling it with the library. But I’m thinking it might make more sense to package the CSS library directly with the component library. This way, users of my component library would get all the necessary styles without extra steps.

What’s the recommended way to handle this? Should I bundle the CSS with the library or keep it separate? I want to ensure the best developer experience for those who will use my component library in the future.

Any advice on best practices for including custom CSS in Angular library projects would be really helpful. Thanks!

hey, i’ve been there! bundling the CSS with ur library is probs the way to go. it’s way easier for devs using ur stuff. just make sure u don’t bloat it too much, ya know?

if it gets huge, maybe split some optional styles into a separate package. but keep the core stuff bundled. makes life easier for everyone!

As someone who’s been down this road before, I would recommend bundling your custom CSS library with your Angular component library. This approach simplifies the process for end-users by eliminating the need to import or manage separate CSS dependencies, while also ensuring that the right version of the CSS matches your components. This self-contained method helps reduce potential style conflicts.

You can achieve this by using Angular’s built-in style encapsulation or by packaging the CSS file to be included during installation. Note that if the CSS library is particularly large or used elsewhere, keeping it separate might prevent unnecessary bloat, though bundling tends to offer a more plug-and-play experience for most projects.

From my experience, bundling your CSS with the component library is the way to go. It creates a smoother integration process for developers using your package. They won’t have to worry about importing styles separately or version mismatches.

However, there’s a caveat. If your CSS is substantial, it could bloat the package size. In that case, you might want to consider keeping it separate and documenting the necessary import steps clearly.

One approach I’ve found effective is to use a hybrid method. Bundle essential styles directly with components, but offer an optional separate CSS package for more extensive theming options. This gives users flexibility while maintaining ease of use.

Remember to thoroughly test your bundled package to ensure styles are applied correctly across different Angular versions and build setups.