I am running a Rails app in a Docker container but am struggling with my development environment as I can't reliably get javascript changes to propagate through to my app running at localhost.
Description of steps to identify problem:
admin-7c69920b702f68258e99.js"admin.js": "/packs/admin-7c69920b702f68258e99.js"admin-4cf5f7c7d6c5ad665fc6.js. I've tried the following process but it doesn't trigger a refresh of the assets even with cache disabled.
docker-compose upI typically have to stop and start the Rails server a second time to trigger the refresh of assets. This feels a bit too voodoo-like for an effective development environment.
I would like to find a way to reliably ensure that the latest assets are reflected in my development environment without having to manually keep tabs on the asset file names to confirm the refresh has happened.
Is there a trick to getting the assets to reload that I might be missing?
I'm using ruby:2.3.7 and Rails 5.2.2.1
I have managed to resolve the issue and now have live reloading of my javascript assets.
The first issue I had was the easiest to resolve and immediately fixed the problem for team members that were running on their local machine (ie. not in a Docker container).
webpacker.yml has a series of defaults with cache_manifest set to true. This would explain why it felt as though the browser was holding on to an old instruction. Resolved by setting cache_manifest: falseThis didn't immediately resolve the problem for the app running in Docker. Apparently, you need to set webpacker up to run in its own container. See the official webpacker instructions here: https://github.com/rails/webpacker/blob/master/docs/docker.md
I found the following instructions to be most useful: http://paulsturgess.co.uk/blog/2018/01/09/setup-webpacker-webpack-dev-server-with-docker-compose/
docker-compose.yml version: '3'
services:
webpacker:
build: .
environment:
- WEBPACKER_DEV_SERVER_PUBLIC=localhost:3035
- WEBPACKER_DEV_SERVER_HOST=localhost
command: ./bin/webpack-dev-server --inline true
volumes:
- .:/myapp
ports:
- '3035:3035'
docker-compose up --buildThis magically resolves the reloading problem.