Skip to content

helpers.isWebpackDevServer() always returns false (Win 10) #757

@delie

Description

@delie
  • [x ] bug report
  • What is the current behavior?
    helpers.isWebpackDevServer always returns false (when used inside webpack config for anything other than src/index.html page).

To test, add the following line to webpack.common.js then run "npm run server:dev" and then "npm run build:dev" to watch the output.
console.log('DEBUG: helpers.isWebpackDevServer() = ' + helpers.isWebpackDevServer());

I presume it's intended for use by the HtmlWebpackPlugin and the src/index.html page, but if you want to use it elsewhere it breaks. As it's quite a handy function, I am also using it for setting a few other conditional variables inside my webpack config.

  • What is the expected behavior?
  • Expected helpers.isWebpackDevServer() to return TRUE when running "npm run server:dev"
  • Expected helpers.isWebpackDevServer() to return FALSE when running "npm run build:dev"
  • Please tell us about your environment:
    Windows 10, command line.
  • Possible solution:
    Why not do a simple indexOf? e.g.
function isWebpackDevServer() {
    var returnValue = false;
    if (process.argv.length > 1)
        returnValue = (process.argv[1].toLowerCase().indexOf('webpack-dev-server') != -1);
    return returnValue;
}

I might be missing something, but this seems to cover all bases

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions