反应热重装不起作用

时间:2018-05-07 01:38:52

标签: javascript reactjs babeljs livereload hot-reload

我正在尝试使用插件https://www.npmjs.com/package/react-hot-loader来启用热重播。但是热重载不起作用,当我刷新页面时,更改会被反映而不会增加,但这不是实时的。我想当我在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

1 个答案:

答案 0 :(得分:0)

尝试

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