我看到以前有人问过这个问题。但他们都没有为我工作。当我更改代码时,控制台显示
[WDS] 应用热更新...
但我没有看到浏览器中发生的变化。我正在使用最新react-hot-loader
的webpack^2.2.0-rc.0
和相同版本的webpack-dev-server
. 这是我的 webpack 配置文件
const VENDOR_LIBS = [
'react', 'lodash', 'redux', 'react-redux', 'react-dom',
'react-input-range', 'redux-form', 'fabric'
];
module.exports = {
entry: {
bundle: './src/index.js',
vendor: VENDOR_LIBS
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[chunkhash].js',
// publicPath: 'dist/'
},
module: {
rules: [
{
loader: ExtractTextPlugin.extract({
loader: 'css-loader'
}),
test: /\.css$/,
},
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/,
},
{
use: [
{
loader: 'url-loader',
options: { limit: 40000 }
},
'image-webpack-loader'
],
test: /\.(jpe?g|png|gif|svg|woff|woff2|eot|ttf)$/,
},
],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}),
new ExtractTextPlugin('style.css'),
new webpack.optimize.AggressiveMergingPlugin(),
],
devServer: {
historyApiFallback: true,
hot: true
},
};
babelrc
{
"presets": ["babel-preset-env", "react"],
"plugins": ["transform-object-rest-spread"],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
}
}
}
index.js
const App = () => {
const store = createStore(reducers, {}, applyMiddleware());
return (
<Provider store={store}>
<ConvertImage />
</Provider>
);
};
ReactDOM.render(<App />, document.getElementById('root'));
我system.imports
在路由中使用异步路由。