1
0

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 3 years have passed since last update.

Docker for Windows で webpack dev server のオートリロード(ファイル監視)が動作しない場合の解決策

Last updated at Posted at 2020-08-17

結論

うまく動かなかったら watchOptions.poll を試してね、とのこと。

If watching does not work for you, try out this option. Watching does not work with NFS and machines in VirtualBox.

webpack 公式ドキュメント より。

設定例

http://localhost:8080 で動作する最小限の記述になります。

本件以外では webpack.config.jshostdocker-compose.ymlworking_dirports あたりがハマりポイントになるかと思います。

webpack.config.js
const path = require('path');

module.exports = {
    mode: 'development',
    entry: path.join(__dirname, 'src', 'index.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js',
    },
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        host: '0.0.0.0',
        port: 8080, // default
    },
    watchOptions: {
        poll: 1000
    }
};
docker-compose.yml
version: '3'
services:
  app:
    image: node:12
    working_dir: /app
    volumes:
      - .:/app
    ports:
      - 8080:8080 # port は devServer と揃える必要がある
    command: npm start
package.json
{
  "name": "app",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "webpack",
    "start": "webpack-dev-server"
  },
  "devDependencies": {
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
  }
}

以上です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?