Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

415
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda