What's the best way to import CSS from node_modules? #4068
-
I'm using https://splidejs.com/integration/react-splide/ in my Remix project. The regular way would be to import css as follows: What would be the Remix way of doing this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
That's kind of the correct way to import CSS from node_modules. First you have to make sure you are importing an actual CSS file. Unlike WebPack, Remix only supports raw imports. You may have to dig around in node_modules to find the CSS file. Also remember that Remix only returns the URL for that asset. You still need to export a links function so Remix knows to serve that CSS to the user. // import the asset (splideCss is the URL like /build/_assets/splide.css)
import splideCss from '@splidejs/react-splide/dist/css/splide-core.min.css'
export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: splideCss }
] |
Beta Was this translation helpful? Give feedback.
-
For me, this did not work: import styles from 'my-library/dist/style.css' so I had to: import styles from 'node_modules/my-library/dist/style.css'` |
Beta Was this translation helpful? Give feedback.
That's kind of the correct way to import CSS from node_modules. First you have to make sure you are importing an actual CSS file. Unlike WebPack, Remix only supports raw imports. You may have to dig around in node_modules to find the CSS file.
Also remember that Remix only returns the URL for that asset. You still need to export a links function so Remix knows to serve that CSS to the user.