Including css files #406
-
Hey! Picked up ViewComponent for a new rails project, but I'm unable to get the component to render with css. Reading the docs and tests, I assumed the css is intended to be loaded automagically based on the component name. Does it have to be explicitly imported? This is as both as a sidecar asset and in a sidecar directory. I started using the latest master, just in case I was on an older version.
Creating a new component rails generate component Example --template-engine erb /* app/app/components/example_component.css */
div {
color: red;
} <%# app/app/components/example_component.html.erb %>
<div>Add Example template here</div> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@sbaildon You'd still need to import the CSS file in an "index" file somewhere as part of your Webpacker pipeline. The location of the file doesn't automatically include it in the Webpack bundle. Also it wouldn't be scoped in the way you think — that example would make all |
Beta Was this translation helpful? Give feedback.
@sbaildon You'd still need to import the CSS file in an "index" file somewhere as part of your Webpacker pipeline. The location of the file doesn't automatically include it in the Webpack bundle. Also it wouldn't be scoped in the way you think — that example would make all
div
tags everywhere red. You can scope by CSS class names, data attributes, or using custom elements/web components (my personal favorite). Happy to supply reference links if you're curious.