1.3 how to import css from npm package?

I’m trying to use the css from this npm package :

https://www.npmjs.com/package/react-select

in my Main.less file I tried
@import '/node_modules/react-select/react-select.min.css';

I get the message
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://localhost/node_modules/react-select/react-select.min.css".

The styles don’t appear visually. How do I go about importing this css ?

2 Likes

Are you able to fix this?

I haven’t figured it out yet, no. As a workaround I copied the css file from the npm package to where I put my other css files in my Meteor project.

An alternative to copying the css file, is creating a symbolic link from somewhere in your meteor project, to the css file in the node_modules folder. You can check this symbolic into git, and meteor will pick it up like a normal file.

I would like to know if there is a proper way to do this.
Symlinking is smart, but there should be a better way

I was looking at this: https://github.com/fourseven/meteor-scss/issues/165 and don’t know if this already works

Just hit the same issue, I need to import the css from a react control. How do you actually go about creating a symlink? Is that a file shortcut/pointer at the filesystem level or is it a line you add to one of the config files?

This is at the file system level.

Ok so first identify the css file(s) you need in the node_modles/your-react-control folder. Then, from somewhere in your Meteor project, for example a client/styles folder

osx, create a symlink in the terminal:

# we are in my-meteor-project/client/styles
ln -s ../../node_modles/your-react-control/dist/styles.css your-react-control.css
3 Likes

Perfect, many thanks @marbemac

There is an issue open for this already: https://github.com/meteor/meteor/issues/6037, it looks like @benjamn has put this into a post-1.3 bucket and will come back to it after 1.3… Maybe we can all add our thoughts in the Github issue, seems like importing CSS for a native NPM package would be important for 1.3 imo.

5 Likes