Skip to content

Need better docs for CSS modules and howto for static images/fonts #197

Closed
@jamesmccann-zz

Description

@jamesmccann-zz

Wondering if there are any good ideas and/or best practice techniques for serving images/fonts in a Rails/Webpack bundle configuration. At present I have a React app being bundled with Webpack into assets/javascripts. CSS Modules are being handled inline using Webpack's css-loader in modules mode, and my output bundle is deployed to app/assets/javascripts and served via the Asset Pipeline.

I'm looking for a tidy solution for handling images. I would like to be able to reference the images in my JS/CSS before being bundled by Webpack. One possible solution I stumbled upon was using file-loader to emit the image files into the bundle location, which might be able to give something like the following:

   |-app
   |---assets
   |-----images
   |-------daa9b80bc018404d6a944c220823751d.png <--- exported by file-loader
   |-----javascripts
   |-------bundle.js
   |-webpack
   |---assets
   |-----images
   |-------logo.png
   |-----javascripts
   |-------index.js <--- references webpack/assets/images/logo.png

And the image is then served by Rails. Has anyone tried this and had any luck with a solution?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions