Skip to content

What's the best way to import CSS from node_modules? #4068

Closed Answered by kiliman
christian-reichart asked this question in Q&A
Discussion options

You must be logged in to vote

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 }
]

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@christian-reichart
Comment options

Answer selected by christian-reichart
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants