How to detect if webpack-dev-server is running?
Either:
const isDevServer = process.argv[1].indexOf('webpack-dev-server') !== -1;
or:
const isDevServer = process.argv.some(v => v.indexOf('webpack-dev-server') !== -1);
or:
const isDevServer = process.argv.some(v => v.includes('webpack-dev-server'));
I've been using the latter to a great effect. One configuration FTW!
Update: The environment variable is changed to WEBPACK_SERVE
.
The webpack dev server will now set the WEBPACK_DEV_SERVER
environment variable, allowing for a more robust way to check.
const isDevServer = process.env.WEBPACK_DEV_SERVER;