React NPM Components with CSS?

Perhaps this is just me showing my inexperience with React, Browserify, etc. But I am trying to use a react component, in the way suggested by this article: https://react-in-meteor.readthedocs.org/en/latest/client-npm/

Which I believe is still the recommended way to do things?!

However, the package in question "react-select" has both JS and CSS as part of the package. The JS seems to load perfectly fine, but the CSS is seemingly nowhere to be seen. So how exactly does one go about including the CSS into the build? Iā€™m currently using the Meteor Chef react base as a testing ground at the moment, and in the application.scss Iā€™ve tried adding a path to the packageā€™s CSS, eg. @import "../../packages/npm-container/.npm/package/node_modules/react-select/dist/default.css"; but that doesnā€™t seem to work.

Iā€™ve seen something called npm-css which looks like it might help, but Iā€™m not entirely sure, as itā€™s not built with Meteor in-mindā€¦

What else am I left with as options?

I dont know if there is a better solution, but Iā€™m copying the css into my package and adding
api.addFiles(ā€˜styles/react-select.cssā€™) to packege.js

On linux, Iā€™d do this by making a symbolic link into the public folder:

cd public
ln -s ../../../../wherever/is/the.css the.css

Because the link is relative, it can be commited to git.

Thanks for the answers guys, and donā€™t get me wrong, theyā€™ll both work, but my god, I was hoping for a slightly more elegant / ā€œofficialā€ way. Is there really nothing more robust?

1 Like

So react-select declare a field ā€œstyle: dist/default.cssā€ in package.json. This field seems to be used by certain utilities, like the parcerify plugin for browserify. Since meteor-react is using cosmos:browserify (for now) it may be possible to configure browserify to use parserify to bundle the css for you.

This is the kind of solution that I was more on about; itā€™s just a shame that thereā€™s no guide or official ā€œwayā€ to do it. But thanks for the tips, Iā€™ll take a look at partialify now. :wink:

EDIT: I looked for parcerify, but I think you meant partialify.