5
5

More than 5 years have passed since last update.

Windows で webpack --watch が効かない時

Posted at

概要

macOS で元気に動いていた webpack-dev-server が Windows 10 でファイルの更新にうんともすんとも言わなくなったことの対応です

webpack --watch でも同様です

結論

パスを作るところでは path.join を使います

以前の設定

webpack.confg.js
const path = require("path")

module.exports = {
  context: __dirname + "/src",
  entry: {
    javascript: './main.js'
  },
  output: {
    path: __dirname + "/js",
    filename: "bundle.js",
    publicPath: "js"
  },
  module: {
    preLoaders: [
      {
        test: /\.js$/,
        loader: "eslint",
        exclude: /node_modules/
      }
    ],
    loaders: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/
      }
    ]
  }
}

現象

こういうパスが生成されていましたが

C:\path\to/src\main.js

こうあるべきです

D:\path\to\src\main.js

修正後の設定

webpack.confg.js
const path = require("path")

module.exports = {
  context: path.join(__dirname, "src"),
  entry: {
    javascript: './main.js'
  },
  output: {
    path: path.join(__dirname, "src"),
    filename: "bundle.js",
    publicPath: "js"
  },
  module: {
    preLoaders: [
      {
        test: /\.js$/,
        loader: "eslint",
        exclude: /node_modules/
      }
    ],
    loaders: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/
      }
    ]
  }
}
5
5
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
5