2016-01-07 18 views
9
私が使用

時の減速状態を維持する方法は+ Reduxの + のWebPACK + WebpackDevserverを反応します。ホットローダーが起動すると、すべてのレデューサーが初期状態にリセットされます。Reduxのは - ホットリロード

どういうわけか私のレデューサーを実際の状態に保つことはできますか?

entry: [ 
    "./index.jsx" 
], 
output: { 
    filename: "./bundle.js" 
}, 
module: { 
    loaders: [ 
     { 
      test: /\.js|\.jsx$/, 
      exclude: /node_modules/, 
      loaders: ["react-hot","babel-loader"], 
     } 
    ] 
}, 
plugins: [ 
    new webpack.HotModuleReplacementPlugin() 
] 

マイ減速統計:

バベル6、あなたと仮定すると
"start": "webpack-dev-server", 

答えて

14

const initialState = { 
... 
} 

export default function config(state = initialState, action) { ... 

私はちょうどで私のWebPACKのDev-Serverを起動

私のWebPACKの設定が含まれてい

これに沿って何かをする必要があります:

import {createStore} from 'redux'; 
import rootReducer from '../reducers'; 

export default function configureStore(initialState) { 
    const store = createStore(rootReducer, initialState); 

    if(module.hot) { 
    // Enable Webpack hot module replacement for reducers 
    module.hot.accept('../reducers',() => { 
     const nextReducer = require('../reducers/index').default; 

     store.replaceReducer(nextReducer); 
    }); 
    } 

    return store; 
} 

あなたは私のredux demoで動作中のアプローチを見ることができます。

+1

これは、レデューサーフォルダのホットリロードのみをサポートしているようですが、コンテナ、コンポーネント、アクションのホットリロードはどうすればいいですか? – ruandao

+3

コンテナとコンポーネントは[react-hot-loader](https://github.com/gaearon/react-hot-loader)を経由することができます。しかし、少し実験的な技術です。問題は減速機に限られていたので、その理由は限られています。 –

関連する問題