Webpack-dev-server: How to detect from within a plugin whether the webpack is running a single build or a webpack-dev-server?

Created on 29 Oct 2015  路  6Comments  路  Source: webpack/webpack-dev-server

This plugin should only work when webpack is executed as a webpack-dev-server, https://github.com/gajus/write-file-webpack-plugin.

How do I detect within the plugin script whether the webpack is running a single build or a webpack-dev-server?

4 (nice to have)

Most helpful comment

Whats about setting a simple environment variable?

All 6 comments

I have a very hacky workaround for this:

var IS_DEV_SERVER = process.argv[1].indexOf('webpack-dev-server') >= 0;

This will not work if webpack-dev-server is started programmatically.

Why would you need to detect this? You're programmatically starting the webpack dev server so you should know when it's being ran.

@gajus, do you need this also for webpack-dev-middleware users? If so, you could check compiler.outputFileSystem. See also this line.

@SpaceK33z thats what we are already doing

https://github.com/gajus/write-file-webpack-plugin/blob/b5ec5c82b06109dd4d68b2bab4904845262290f3/src/index.js#L17

It feels a bit hacky though.

Otherwise, it works.

Whats about setting a simple environment variable?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mischkl picture mischkl  路  3Comments

Ky6uk picture Ky6uk  路  3Comments

tulika21-zz picture tulika21-zz  路  3Comments

hnqlvs picture hnqlvs  路  3Comments

mrdulin picture mrdulin  路  3Comments