5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails環境でwebpack-dev-serverのHot Module Replacementをdocker-composeで使えるようにする

Last updated at Posted at 2019-03-26

Hot Module Replacementについて詳しくはこちらで。

自分はRails 5.2.1の環境で使いたかったので設定してみました。
まずは、config/webpacker.ymldev_serverhmrの部分をtrueにします。

config/webpacker.yml
〜(略)〜
development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: true # ここ
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/
〜(略)〜

docker-compose.ymlでの対象のホスト名を環境変数で指定して、ポートが通るようにする。

docker-compose.yml
version: '3'
services:
  web:
    build: .
    command: foreman start
    volumes:
      - .:/app
    environment:
      - DOCKER_DB_HOST=db
      - WEBPACKER_DEV_SERVER_HOST=web # ここ(servicesで指定している名前を設定する)

    ports:
      - "3000:3000"
      - "3035:3035" # ここ
    depends_on:
      - db
〜(略)〜

起動でForeman使っているのでProcfilewebpack-dev-serverの分を追加。

web: bin/rails s -p 3000 -b '0.0.0.0'
webpack-dev-server: bin/webpack-dev-server <- 追加

あとは起動するだけ。

docker-compose up -d
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?