I've set up WebPack successfully - it's compiling my babel and SCSS files just fine, and I got the watch functionality to work fine. But I'd also like to work with the Hot Module Replacement - and I'm having difficulties getting it going. When I load the dev server in my browser it shows Cannot resolve module 'webpack/hot/dev-server'
. My config looks like this:
import webpack from 'webpack';
import wpServer from 'webpack-dev-server';
var compiler = webpack({
entry: [
'./src/core.js',
'webpack/hot/dev-server'
],
output: {
path: outPath,
filename: '[name].js'
},
resolveLoader: { root: path.join(MODULE_PATH, "node_modules") },
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.scss$/, loader: "style!css!sass" }
]
},
plugins: [new webpack.HotModuleReplacementPlugin()],
watch: true
});
var server = new wpServer(compiler, {
contentBase: outPath,
hot: true,
quiet: false,
noInfo: false,
lazy: true,
filename: "main.js",
watchDelay: 300,
headers: { "X-Custom-Header": "yes" },
stats: { colors: true },
});
server.listen(8080, "localhost", function() {});
and my index.html contains:
<script src="http://localhost:8080/webpack-dev-server.js"></script>
<script src='main.js'></script>
Does anyone have any ideas?
If you installed webpack-dev-server
globally, which is npm install webpack-dev-server -g
, try install it locally (just remove the option -g
).
I solved this problem by doing so.