Skip to Content
Modern Front-End Development for Rails
book

Modern Front-End Development for Rails

by Noel Rappin
June 2021
Intermediate to advanced
398 pages
9h 35m
English
Pragmatic Bookshelf
Content preview from Modern Front-End Development for Rails

Adding CSS and Assets to webpack

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​)
 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern Front-End Development for Rails, 2nd Edition

Modern Front-End Development for Rails, 2nd Edition

Noel Rappin
Agile Web Development with Rails 6

Agile Web Development with Rails 6

Sam Ruby, David B. Copeland, Dave Thomas

Publisher Resources

ISBN: 9781680508758Errata Page