Is it possible to make this work without npm but with importmap #2135
-
Hello :) I am pretty new to javascript, i have a rails 7 that does not have npm or yarn installed and that is for now only using importmaps. I would like to use the primer CSS to support the view components. Is it possible to have primer/css without npm, only using importmaps ? Thank you so much for your help, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hey @troptropcontent, interesting question! I have personally never used import maps before, but after reading a bit about them I think primer/view-components should work with them. Try putting something like this in config/importmap.rb: pin "@primer/view-components", to: "https://ga.jspm.io/npm:@primer/[email protected]/app/assets/javascripts/primer_view_components.js" As for the CSS from primer/view-components and primer/css, you should be able to pull them in directly using <link rel="stylesheet" href="https://unpkg.com/@primer/[email protected]/app/assets/styles/primer_view_components.css" crossorigin="" />
<link rel="stylesheet" href="https://unpkg.com/@primer/[email protected]/dist/primer.css" crossorigin="" /> |
Beta Was this translation helpful? Give feedback.
-
I notice this in the guides - https://primer.style/product/getting-started/rails/#import-maps
What is the state as of Aug 2025? |
Beta Was this translation helpful? Give feedback.
-
Hey there @dereke 👋 Unfortunately I am no longer with GitHub, but given my past experience working on this library and my knowledge of the dynamics of the Primer team, I am 99% sure nothing has changed with regard to using PVC with importmaps. That is to say, it is still not possible to use PVC with importmaps for the reason mentioned in the documentation. One way to avoid the import issue might be to include individual compiled javascript files, one per component, to the build output. You could then pull in the components you actually need instead of the whole thing, and hopefully you only need components that don't attempt to import 3rd party modules. That's really just a band-aid though. |
Beta Was this translation helpful? Give feedback.
Hey @troptropcontent, interesting question! I have personally never used import maps before, but after reading a bit about them I think primer/view-components should work with them. Try putting something like this in config/importmap.rb:
As for the CSS from primer/view-components and primer/css, you should be able to pull them in directly using
<link>
tags: