Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

417
Vistas
Webpacker & Rails Asset Pipeline in Docker - View is not pointing to updated JS asset

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:

  • If I refresh the view I can see in the console that webpacker is compiling.
  • It generates a new cache-busted asset in public/packs admin-7c69920b702f68258e99.js
  • The manifest.json reflects this update "admin.js": "/packs/admin-7c69920b702f68258e99.js"
  • I can refresh the view repeatedly and yet the network tab shows that the old asset is called admin-4cf5f7c7d6c5ad665fc6.js.

I've tried the following process but it doesn't trigger a refresh of the assets even with cache disabled.

  • Refresh the view in the browser to trigger webpack compile
  • Restart the Rails server by crashing out of Docker and running docker-compose up
  • Refresh the view

I 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

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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).

  • The webpacker config file 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: false

This 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/

  • So I've added the following to my 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'
  • Then run docker-compose up --build

This magically resolves the reloading problem.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda