...

/

Compiling Assets with Webpacker

Compiling Assets with Webpacker

We will learn to add Webpacker in our Compose.

webpack-dev-server

As part of Webpacker, Rails provides the webpack-dev-server binary. This is a small server that runs in the background, automatically compiling our webpack-managed files.

If you were developing locally, this would just be another command you would issue from your terminal. However, the Docker way is to run this as a separate service in its own container.

Modification of Compose

Let’s add a new service for it to our docker-compose.yml file:

Press + to interact
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=webpack-dev-server
webpack-dev-server:
build: .
command: ./bin/webpack-dev-server
ports:
- 3035:3035
volumes:
- .:/usr/src/app
env_file:
- .env/development/web
- .env/development/database
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:

Explanation

...