Import whole directory in Webpack(er)
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
Like an amateur I've been importing all my assets one-by-one when using Webpacker to get them all listed in the app manifest. It's annoying when adding or removing an image to then update the reference in images/index.js
.
Turns out, there's a better way and you can reduce it all down to one single line of code. Use require.context
and pass a regular expression to identify which files you want to import. Boom.