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

Gaurav Saini @sainig

About: Proud coder, gaming lover, traveller, cooking enthusiast, but sometimes I’m like (╯°□°)╯︵ ┻━┻

Location:
Jaipur, India
Joined:
Jan 27, 2020

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

Publish Date: Apr 17 '20
2 1

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

Comments 1 total

  • Víctor Navarro
    Víctor NavarroApr 17, 2020

    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

Add comment