1. Installation
NPM Install Webpack-dev-server React-hot-loader--save-dev
2, Configuration Server.js
varWebpack = require (' Webpack '));varWebpackdevserver = require (' Webpack-dev-server '));varConfig = require ('./webpack.config '));Newwebpackdevserver (webpack (config), {publicPath:config.output.publicPath, hot:true, Historyapifallback:true}). Listen (, ' localhost ',function(err, result) {if(Err) {Console.log (err); } console.log (' Listening at localhost:3000 '); });
3, Configuration Webpack.config.js
varWebpack = require (' Webpack ')); Module.exports={entry: {//index: './js/index.js 'index: [' webpack-dev-server/client?http://localhost:3000 ', ' Webpack/hot/dev-server ', './js/index.js ']}, Output: {path:'/js/', FileName:' [Name].bundle.js ', Publicpath:'/js/'}, module: {loaders: [/*{test:/\.jsx?$/, exclude:/(node_modules|bower_components)/, loader: ' B Abel '}, {loader: ' exports '},*/{test:/\.jsx?$/, Loader:' React-hot!babel ', exclude:/(node_modules|bower_components)/}]}, resolve: {extensions: [', '. js ', '. Jsx ']}, plugins: [//new Webpack.optimize.CommonsChunkPlugin (' Common.js '), NewWebpack. Hotmodulereplacementplugin (),NewWebpack. Noerrorsplugin ()]};
4. Start
Node server
You can also configure the NPM command to add the following code to the Package.json
"Scripts": { "start": "Node./server-webpack.js"}
Run command
Start
Webpack Dev Server + React Hot Loader