Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

概要

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/
      }
    ]
  }
}
ryohey
covelline
もっと楽しい明日をつくる
http://covelline.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away