简体   繁体   English

尽管我已经完成了“内联:真”,但 Webpack 开发服务器热重载无法与 reactjs 一起使用?

[英]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?为什么热模块更换在 webpack 开发服务器上停止工作?

My package.json file:我的package.json文件:

{
  "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: webpack.config.js文件:

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.以前我遇到 CSS 加载器问题,在webpack.config.js中添加加载器后,我停止了 webpack。 how can I make Hot module work?如何使 Hot 模块工作?

您需要激活 Hot Module Replacement Plugin,完整说明: https ://webpack.js.org/guides/hot-module-replacement/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM