Closed
Description
A lot of times when somebody has problems with webpack-dev-server CLI, I suggest them use Node API instead and their problem disappears. Here's two recent issues I've seen.
Take this sample project from gaearon/react-hot-loader#77.
Run node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --hot --port 8080
. Change a file. HMR will work but will output Uncaught RangeError: Maximum call stack size exceeded
on every update.
Then add a server.js
that should by all means be identical to the call above:
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
hot: true
}).listen(8080, 'localhost');
Magically, this doesn't work at all. The reason is because WebpackDevServer doesn't read publicPath
from Webpack config. I always end up passing it manually. Why is this necessary?
Okay, let's pass it manually:
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
hot: true,
publicPath: config.output.publicPath
}).listen(8080, 'localhost');
Voila! RangeError
is gone.
- Why does CLI and Node API behave differently? One gives
RangeError
, another one works. - Why won't CLI infer
publicPath
from Webpack config?