5

I have a Rails 6 app I return to sporadically. It's using webpacker for the JS, and Sprockets for the CSS (as I think is default). If relevant, I'm developing on WSL - the files are in the Ubuntu filesystem, Rails is running in Ubuntu, editing is using VSCode remotely into the WSL.

Today, running in development environment, I made a change to one of the SCSS files and refreshed my page. The served CSS did not update; Sprockets has not recompiled it. Stopping and restarting the server did not prompt a recompile (I didn't really expect it to...).

bin/rails assets:precompile did regenerate; but I wouldn't expect to have to do that in development.

How do I make Rails recompile changed SCSS in the sprockets asset pipeline in development?


Extracts of my files and setups that I think should be relevant:

app/assets/config/manifest.js

//= link_tree ../images
//= link_directory ../stylesheets .css

app/assets/stylesheets/application.scss

/*
 *= require_tree .
 *= require_self
 */
...

app/assets/stylesheets/ also contains characters.scss, which is the file I modified.

app/views/layouts/application.html.slim

doctype html
html
  head
    = csrf_meta_tags
    = csp_meta_tag
    = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
...

config/environments/development.rb

...
  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = false
  config.assets.compile = true

# ^-- also fails if compile = false
...

Gemfile.lock

...
    rails (6.0.3.2)
      actioncable (= 6.0.3.2)
      actionmailbox (= 6.0.3.2)
      actionmailer (= 6.0.3.2)
      actionpack (= 6.0.3.2)
      actiontext (= 6.0.3.2)
      actionview (= 6.0.3.2)
      activejob (= 6.0.3.2)
      activemodel (= 6.0.3.2)
      activerecord (= 6.0.3.2)
      activestorage (= 6.0.3.2)
      activesupport (= 6.0.3.2)
      bundler (>= 1.3.0)
      railties (= 6.0.3.2)
      sprockets-rails (>= 2.0.0)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.4.0)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    sprockets (4.0.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
...
Chowlett
  • 45,935
  • 20
  • 116
  • 150

1 Answers1

13

It looks like my setup was correct, but I hadn't realised that Rails will prefer a precompiled asset if one exists.

After I ran bin/rails assets:clobber to remove the compiled versions, it went back to live-updating.

Chowlett
  • 45,935
  • 20
  • 116
  • 150