0

The page loads up correctly and even logs to client console [WDS] Hot module replacement enabled. But when I make changes to files nothing is reflected on the page. Even on reload. Only when restarting the server.

Not sure if this matter but Im using 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!
      }]]
    }
  }
}
Daniel Kobe
  • 9,376
  • 15
  • 62
  • 109

2 Answers2

0

Try adding

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

in your package.json file, and use npm start.

Electric Sheep
  • 3,867
  • 1
  • 29
  • 38
Mehmoodul haq
  • 316
  • 3
  • 9
0

adding additional entry point in webpack config will reload the page automatically, however you will loose all the state because of a refresh.

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

and in server js

app.use(require('webpack-hot-middleware')(compiler));
abhirathore2006
  • 3,317
  • 1
  • 25
  • 29