GD- Ganesh Deshmukh
GD- Ganesh Deshmukh

Reputation: 1554

Webpack dev server hot reloading not working with reactjs, though i have done "inline:true"?

Why does Hot Module Replacement stop working on webpack dev server?

My package.json file:

{
  "name": "routing-react",
  "version": "1.0.0",
  "description": "Just a little ReactJS Training Ground",
  "main": "index.js",
  "scripts": {
    "start": "npm run build",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
    "build:prod": "cp src/index.html dist/index.html && webpack -p"
  },
  "keywords": [
    "react"
  ],
  "author": "gd10",
  "license": "MIT",
  "dependencies": {
    "css-loader": "^0.28.9",
    "react": "^15.1.0",
    "react-dom": "^15.1.0",
    "react-hot-loader": "^3.1.3",
    "style-loader": "^0.20.1",
    "webpack-hot-middleware": "^2.21.0"
  },
  "devDependencies": {
    "babel-loader": "^6.4.1",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-2": "^6.11.0",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1"
  }
}

I have also set:

devserver = {
    historyApiFallback: true,
    inline: true,
    hot: true
}

But it didn't helped.

webpack.config.js file:

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

var DIST_DIR = path.resolve(__dirname, 'dist');
var SRC_DIR = path.resolve(__dirname, 'src');

var config = {
    devServer: {
        historyApiFallback: true,
        contentBase: './',
        inline: true,
        hot:true,
        port: 3004,
    },
    entry: SRC_DIR + '/app/index.js',
    output: {
        path: DIST_DIR + '/app',
        filename: 'bundle.js',
        publicPath: '/app/'
    },
    module: {
        loaders: [
            {
                test: /\.js?/,
                include: SRC_DIR,
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2015', 'stage-2']
                }
            },
            {
                test: /\.css?/,
                loader:'style-loader!css-loader'
            },
        ]
    }
};

module.exports = config;

Previously I had CSS loaders issue and after adding loaders in webpack.config.js I got webpack stopped. how can I make Hot module work?

Upvotes: 0

Views: 9090

Answers (1)

Fernando Montoya
Fernando Montoya

Reputation: 2644

You need to activate the Hot Module Replacement Plugin, full instructions: https://webpack.js.org/guides/hot-module-replacement/

Upvotes: 0

Related Questions