React-redux 应用不再自动更新

Posted

技术标签:

【中文标题】React-redux 应用不再自动更新【英文标题】:React-redux app is no longer auto updating 【发布时间】:2017-12-18 19:47:12 【问题描述】:

我有一个 react-redux 应用程序运行良好,每次文件更改后 UI 都会自动更新,然后我决定将 sass 插入我的应用程序并且自动重新加载停止工作。所以为了在我的应用程序中获得 sass,我必须安装 sass-loader、node-sass、css-loader 等。但是其中一个加载器需要 webpack 2,所以我从 1.15 切换到 2.0,现在当我运行“ npm run dev" 每次文件更改后我都会看到 webpack 重新编译,但我的 UI 没有在浏览器中自动重新加载。谁能帮我解决这个问题?

这是我的 webpack 配置文件:

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');

module.exports = 
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/app.js",
  module: 
    loaders: [
      
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader',
        query: 
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy', "transform-object-rest-spread"],
        
      ,
      
        test: /\.scss$/,
        loader: 'style-loader!css-loader!sass-loader'
      
    ]
  ,
  output: 
    path: __dirname + "/src/",
    filename: "app.min.js"
  ,
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin( mangle: false, sourcemap: false ),
  ],
;

这是我的 package.json 文件:


  "name": "campaign-viewer",
  "version": "0.0.0",
  "description": "Code challenge from MediaMath",
  "main": "webpack.config.js",
  "dependencies": 
    "axios": "^0.12.0",
    "babel-core": "^6.18.2",
    "babel-loader": "^6.2.0",
    "babel-plugin-add-module-exports": "^0.1.2",
    "babel-plugin-react-html-attrs": "^2.0.0",
    "babel-plugin-transform-class-properties": "^6.3.13",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-stage-0": "^6.3.13",
    "css-loader": "^0.28.4",
    "moment": "^2.18.1",
    "node-sass": "^4.5.3",
    "react": "^0.14.6",
    "react-datetime": "^2.8.10",
    "react-dom": "^0.14.6",
    "react-redux": "^4.4.5",
    "redux": "^3.6.0",
    "redux-logger": "^2.6.1",
    "redux-promise-middleware": "^3.2.0",
    "redux-thunk": "^2.1.0",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.18.2",
    "webpack": "^2.0.0",
    "webpack-dev-server": "^1.14.1"
  ,
  "devDependencies": ,
  "scripts": 
    "dev": "./node_modules/.bin/webpack-dev-server --content-base src --inline --hot",
    "test": "echo \"Error: no test specified\" && exit 1"
  ,
  "author": "Chris Stephenson",
  "license": "ISC"

【问题讨论】:

【参考方案1】:

看起来问题出在使用 webpack-dev-server 上。当我使用版本 2.0.0 而不是 1.14.1 时,它再次开始自动重新加载。

【讨论】:

以上是关于React-redux 应用不再自动更新的主要内容,如果未能解决你的问题,请参考以下文章

当我滚动时,uitableviewcell 中的 UIslider 不再自动更新

android 怎么更新友盟sdk

在 react-redux 应用程序中更新部分状态时,整个页面闪烁并跳转到顶部

React-redux 存储更新,但 React 没有

怎么可以禁止火狐自动更新

mysql如何让时间属性不自动更新