June 2021
Intermediate to advanced
398 pages
9h 35m
English
You might want to use a lot of static file assets via Webpacker, such as images or fonts, in your code or CSS. To get those assets into our pack file we have to import them, and then Webpacker gives us some helper methods to be able to access the files. We need helper methods here because bundling the images into the pack changes the name of the file, so we can’t just 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 boilerplate from the Webpacker gem, which I removed along the way; we can put it back now:
| | const images = require.context("../images", true) |
| | |