Search code examples
ruby-on-railswebpacker

how to get webpacker to load css if extract_css is false


I have the following pack file:

// app/javascript/packs/styles.js 
import 'bootstrap/dist/css/bootstrap'

Unless I set extract_css: true in config/webpack.yml I do not see how to get these styles to load.

If I set extract_css: true and include <%= stylesheet_pack_tag 'styles' %> in the layout everything seems to work.

But then what is the point of extract_css: false why would you ever NOT want this? Because its the default webpacker configuration I feel as if I am missing something important.


Solution

  • With extract_css: false, the styles are provided by the webpack js runtime as blob urls and injected into the document <head> inline (assuming you have a corresponding javascript_pack_tag).

    One use case for this approach in development is to better support hot module reloading for CSS.