Webpack Dev服务器没有观察或更新文件

时间:2016-07-03 17:40:58

标签: reactjs webpack webpack-dev-server

因此,webpack不会更新我所做的任何更改,也不会将build.js与更改重新绑定。很令人沮丧的问题。不知道这笔交易是什么。可以真的使用一些帮助!谢谢!代码如下。

webpack.config.js

var webpack = require("webpack");
var path = require("path");

var DEV = path.resolve(__dirname, "dev");
var OUTPUT = path.resolve(__dirname, "output");

var config = {
  watch: true,
  devtool: 'inline-source-map',
  entry: [
    'webpack-dev-server/client?http://localhost:8080/',
    'webpack/hot/only-dev-server',
    DEV + "/App.jsx"
  ],
  output: {
    path: OUTPUT,
    filename: "build.js"
  },
  module: {
    loaders: [{
        include: DEV,
        loaders: ["react-hot", "babel"],
    }]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
};

module.exports = config;

的package.json

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.10.4",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "react": "^15.2.0",
    "react-dom": "^15.2.0",
    "react-hot-loader": "^1.3.0",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1"
  },
  "babel": {
    "presets": [
      "es2015",
      "react"
    ]
  }
}

我跑了./node_modules/.bin/webpack来获得初始版本。

如果您需要更多信息,请与我们联系。再次感谢。

1 个答案:

答案 0 :(得分:0)

React-Hot-Loader的配置非常具体。我会尝试minimal successful configuration用于React Hot Loader(注意使用类似的路径,而不是通过使用path.resolve进行变量初始化):

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:8080',
    'webpack/hot/only-dev-server',
    './src/App.jsx'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel'],
      include: path.join(__dirname, 'src')
    }]
  }
};