gpt4 book ai didi

javascript - react 热重载不起作用

转载 作者:行者123 更新时间:2023-12-01 17:28:50 27 4
gpt4 key购买 nike

我正在尝试使用插件 https://www.npmjs.com/package/react-hot-loader启用热重载。但是热重载不起作用,当我刷新页面时,更改会在没有构建的情况下反射(reflect)出来,但它不是实时的。我认为每当我将更改保存在 jsx 上时,它应该实时反射(reflect)在 html 上,对吗?如果我错了请指正

我的jsx文件

import { hot } from 'react-hot-loader'

@observer
class ListingComponent extends Component {
render() {
.........
}
}
export default hot(module)(ListingComponent);

//global function to run from other frameworks
window.WB.react.renderListingComponent = function() {
render(

<ListingComponent/>,
document.getElementById('node')

);
}

我的.babelrc

{
"presets" : ["es2015", "react"],
"plugins": ["transform-decorators-legacy","transform-class-properties","lodash","react-hot-loader/babel"]
}

我的 webpack.config.js

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


// var BUILD_DIR = path.resolve(__dirname, 'src/public');
var BUILD_DIR = path.resolve(__dirname, '../assets/js');
var APP_DIR = path.resolve(__dirname, 'src/app');

var config = {
resolve: {
extensions: ['.js', '.jsx']
},
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js',
},

module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
loader : 'babel-loader',
options: {
// This is a feature of `babel-loader` for Webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
plugins: ['react-hot-loader/babel'],
},
}
]
}
};

module.exports = config;

webpack 服务器命令

npm run dev --watch --hot ----output-public-path=/assets/js/ --inline

最佳答案

尝试

echo 999999 | sudo tee /proc/sys/fs/inotify/max_user_watches   

关于javascript - react 热重载不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50206066/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com