DEV Community

Gaurav Saini
Gaurav Saini

Posted on

How to use styles when publishing a react component to npm?

Hey folks,
I'm a newbie to react and this is my first time publishing to npm. I created a react component and wanted to put on the npm registry.

I used create-react-library to build the component and published it to npm. Everything functions perfectly fine when I install my new npm package as a dependency in another react app, but there is no CSS applied to the component

Below image shows my folder structure
https://dev-to-uploads.s3.amazonaws.com/i/nkcwo2a2kd9v1p5mrizy.png

How do I enable/apply styles for the package?

Here's the npm package for reference
https://www.npmjs.com/package/react-step-progress

Thanks

Top comments (1)

Collapse
 
papeloto profile image
Víctor Navarro

The component/s itself should import the CSS with Css modules for example. If you want to use them globally you can import the styles file on the index.tsx file