diff --git a/lib/Server.js b/lib/Server.js index ca1a357a1e..8041b5ef99 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -62,6 +62,10 @@ if (semver.satisfies(process.version, '8.6.0 - 9')) { tls.DEFAULT_ECDH_CURVE = 'auto'; } +if (!process.env.WEBPACK_DEV_SERVER) { + process.env.WEBPACK_DEV_SERVER = true; +} + class Server { constructor(compiler, options = {}, _log) { if (options.lazy && !options.filename) { diff --git a/test/Server.test.js b/test/Server.test.js index 7e05d0e968..23acfaa9bf 100644 --- a/test/Server.test.js +++ b/test/Server.test.js @@ -474,4 +474,30 @@ describe('Server', () => { afterAll(testServer.close); }); }); + + describe('WEBPACK_DEV_SERVER environment variable', () => { + const OLD_ENV = process.env; + + beforeEach(() => { + // this is important - it clears the cache + jest.resetModules(); + + process.env = { ...OLD_ENV }; + + delete process.env.WEBPACK_DEV_SERVER; + }); + + afterEach(() => { + process.env = OLD_ENV; + }); + + it('should be present', () => { + expect(process.env.WEBPACK_DEV_SERVER).toBeUndefined(); + + // eslint-disable-next-line global-require + require('../lib/Server'); + + expect(process.env.WEBPACK_DEV_SERVER).toBe(true); + }); + }); });