开启react-hot-loader ,浏览器仍然会重新加载
来源:2-7 hot-module-replacement

慕神9310363
2018-05-17
参照最新版react-hot-loader的用法,开启了hot-module-replacement. 更改文件时,浏览器还是会重新刷新加载。
App.jsx文件:
app.js文件:
webpack.config.client.js文件:
const path = require('path'); const HTMLPlugin = require('html-webpack-plugin'); const webpack = require('webpack'); const isDev = process.env.NODE_ENV === 'development'; const config = { entry: { app: path.join(__dirname, '../client/app.js') }, output: { filename: '[name].[hash].js', path: path.join(__dirname, '../dist'), publicPath: '/public' }, module: { rules: [ { test: /.jsx$/, loader: 'babel-loader', }, { test: /.js$/, loader: 'babel-loader', exclude: [ path.join(__dirname, '../node_modules') ] } ] }, plugins: [ new HTMLPlugin({ template: path.join(__dirname, '../client/template.html') }), ] } if (isDev) { config.devServer = { host: '0.0.0.0', port: '8888', contentBase: path.join(__dirname, '../dist'), hot: true, overlay: { errors: true }, publicPath: '/public', historyApiFallback: { index: '/public/index.html' } } } module.exports = config;
.babelrc文件:
{ "presets": [ ["es2015", {"loose": true }], "react" ], "plugins": ["react-hot-loader/babel"] }
react-hot-loader官方用法:
写回答
1回答
-
Jokcy
2018-05-18
并不是开启了所有都会热更新,热更新要api支持,react hot loader就是处理了react组件的热重载,其他的文件改了还是会更新。
00
相似问题