Search⌘ K

Adding CSS and Assets to webpack

Explore the process of adding and managing CSS and static assets like images and fonts with Webpacker in Rails. Learn how to import files, use helper methods for asset paths, and reference assets in JavaScript, SCSS, and Rails views to build efficient front-end applications.

Importing files

We might want to use a lot of static file assets from Webpacker, such as images or fonts, in our code or CSS. We have to import them to get those assets into our pack file. Then Webpacker gives us some helper methods to be able to access the files. We need helper methods because bundling the images into the pack changes the name of the file, so we can’t simply use the raw file name.

First we need to import the static files. To do so, we need to add the following code to our application.js. This code is a ...