0

该页面正确加载,甚至记录到客户端控制台[WDS] Hot module replacement enabled。但是当我对文件进行更改时,页面上没有任何反映。即使在重新加载。仅在重新启动服务器时。

不确定这是否重要,但我使用的是 redux。

webpack.config.js

var precss = require('precss');
var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval-source-map',
  entry: __dirname + '/src/index.js',
  output: {
    path: __dirname + '/build',
    filename: 'bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel'
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.css$/,
        loader: 'style!css?modules!postcss'
      },
      { 
        test: /\.(png|jpg|jpeg|gif|woff)$/, 
        loader: 'url-loader?limit=8192' 
      }
    ]
  },

  postcss: function() {
    return [autoprefixer, precss];
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: __dirname + '/src/index.html'
    }),
    new webpack.HotModuleReplacementPlugin()
  ],

  devServer: {
    contentBase: './public',
    colors: true,
    historyApiFallback: true,
    inline: true,
    hot: true
  },

  jest: {
    moduleFileExtensions: ["js", "jsx"]
  }
};

.babelrc

{
  "presets": ["react", "es2015", "stage-0"],
  "env": {
    "development": {
      "plugins": [["react-transform", {
        "transforms": [{
          "transform": "react-transform-hmr",
          "imports": ["react"],
          // this is important for Webpack HMR:
          "locals": ["module"]
        }]
        // note: you can put more transforms into array
        // this is just one of them!
      }]]
    }
  }
}
4

2 回答 2

0

在 webpack 配置中添加额外的入口点将自动重新加载页面,但是由于刷新,您将丢失所有状态。

entry: [
        'webpack-hot-middleware/client?reload=true',
         __dirname + '/src/index.js',
    ],

在服务器 js 中

app.use(require('webpack-hot-middleware')(compiler));
于 2016-07-29T11:13:44.467 回答
0

尝试添加

"scripts": {
    "start": "node_modules/.bin/webpack-dev-server --progress --inline"
},

在你的 package.json 文件中,并使用npm start.

于 2016-07-29T10:17:21.313 回答