LoginSignup
1
1

More than 1 year has passed since last update.

Dockerfileにfrourioのインストールを組み込む - volumes + Webpackの問題

Last updated at Posted at 2021-05-08

DockerfileにfrourioのCLIインストールを記載してビルドしました。
その際、出来上がったコンテナでWebpackの監視が正常に動作していないことに気づきました。

結論から記載すると、Webpackの公式サイトに記載がありますがNFS上の変更イベントは受け取れません。 docker-compose.ymlのvolumes上のファイルを監視する場合、ポーリングで変更を監視することになります。

docker-compose.yml
version: '3.7'
services:
  app:
    # volumes上のファイルをWebpackで監視する場合はポーリングになります
    volumes:
      - /test/:/var/www/html/

frourioのwebpackの設定に下記を追加します。
※下記はfrourioでのインストール後に設定する場合のパスになります

server/webpack.config.js
  // 下記を追加
  watchOptions: {
    ignored: ['**/node_modules'],
    aggregateTimeout: 200,
    poll: 1000
  },

Next.js を選択している場合、プロジェクトルートに「next.config.js」を追加します。

next.config.js
module.exports = {
  webpackDevMiddleware: config => {
    config.watchOptions = {
      ignored: ['**/node_modules'],
      aggregateTimeout: 200,
      poll: 1000
    }

    return config
  }
}

除外設定に「node_modules」を追加していますが、監視が必要な方は除いてください。

※Dockerfileにfrourio自体のインストールを組み込む場合、いろいろ面倒な処理が必要になります。

1
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
1
1