簡體   English   中英

反應熱重載不起作用

[英]React hot reload not working

我正在嘗試使用插件https://www.npmjs.com/package/react-hot-loader來啟用 hot relaod 。 但是熱重載不起作用,當我刷新頁面時,更改會在沒有構建的情況下反映出來,但不是實時的。 我認為當我在 jsx 上保存更改時,它應該實時反映在 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   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM