Skip to content

Server callback is barely useful #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StephanBijzitter opened this issue Mar 15, 2017 · 3 comments
Closed

Server callback is barely useful #847

StephanBijzitter opened this issue Mar 15, 2017 · 3 comments

Comments

@StephanBijzitter
Copy link

Do you want to request a feature or report a bug?
I am not sure whether this is by design (in which case I want to request a change), or a bug.

What is the current behavior?
The callback for listen is called immediately after the server is reachable on the specified port.

If the current behavior is a bug, please provide the steps to reproduce.

const webpack = require('webpack');
const config = require('../webpack.config.server');
const WebpackDevServer = require('webpack-dev-server');

const compiler = webpack(config);
const server = new WebpackDevServer(compiler, config.devServer);

server.listen(config.devServer.port, () => {

});

What is the expected behavior?
I expected the callback to be called after compilation had finished (and all javascript bundles were created). This is because my callback is a testing suite which needs the server online (currently the callback satisfies this), but also needs the files to be already-created.

If this is a feature request, what is motivation or use case for changing the behavior?
I want to request the option to be able to run a function after the initial compiling finishes, so that I can run my test suites.

Please mention your webpack and Operating System version.
webpack ^2, webpack-dev-server ^2, ubuntu 14.04

@SpaceK33z
Copy link
Member

A callback that fires when compilation is finished is available as compiler.plugin('done', cb).

I happen to have made a test suite runner like you have too, this is some code out of mine:

compiler.plugin('done', (stats) => {
    stats = stats.toJson();

    if (stats.errors && stats.errors.length > 0) {
        // show errors
        return;
    }
    // compilation success
});

The .listen callback is by design, there are many cases where you immediately want to do something after the server has started, like show the URL.

@StephanBijzitter
Copy link
Author

Ha, well I'll be damned.

@th3fallen
Copy link

th3fallen commented May 16, 2017

is there a way to catch this error...

      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRNOTAVAIL 10.211.55.5:3000

happens when the host domain doesnt exist on the machine, i want to log an error telling the devs to add a hostfile entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants