webpack2 React热更新配置报错 ?

图片描述

配置按照官网文档进行配置的,运行后一直保错,对于 react-hot-loader/patch 我在 webpack.config.js 中已经写在了 entry 数组的最前部,依然没有效果。

main.js:1 React Hot Loader: It appears that "react-hot-loader/patch" did not run immediately before the app started. Make sure that it runs before any other code. For example, if you use Webpack, you can add "react-hot-loader/patch" as the very first item to the "entry" array in its config. Alternatively, you can add require("react-hot-loader/patch") as the very first line in the application code, before any other imports.

阅读 4.7k
2 个回答
新手上路,请多包涵

像这样写就可以了

const ReactHotLoader = require('react-hot-loader/patch');
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
     entry: [
         //这里是入口文件
         'webpack-dev-server/client?http://0.0.0.0:3000',
         'react-hot-loader/patch',
         './app/index.js'
     ],
     ...
 }

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题