Get log directly from Webpack #143
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Disclaimer
This pull request is not meant to be merged as-is.
The code is a bit ugly and needs reviewing.
It is however a working implementation.
The changes
Now, webpack-dashboard can get the logs directly from Webpack.
Instead of using 2 IPCs (standard output for logs, sockets for everything else) you can now use sockets only.
Usage
To use this, just omit the child command. Hence, the usage would be:
or, for a specific port, say 3001
Motivation
I needed this for myself, and here's why.
Remote webpack process
I run webpack in a container. It is much easier for me to simply connect to the socket than it is to redirect the standard output properly. I first tried that but ended up with contrived commands (and loss of color output).
Multiple webpack entries/outputs
I have a single webpack process that produces two bundles ; one for my app's server, the other for my app's client. Using webpack-dashboard the current way, only data from the last working bundle is processed. A workaround is to specify a different port for each bundle and open webpack-dashboard in two terminals (each connected to a different socket). Problem is, because there is a single webpack process, you can only get the logs for one of those. And nothing guarantees that the logs will match the bundle you're connected to.
More flexible output
I don't have a use case for this but the issue #138 asks for custom log output.
With this change, it would be done like so:
where
<command>
is a command that outputs custom logs in standard output.The code
I think this design is simpler and more elegant. However, the code is not that great.
In
bin/webpack
there is a bunch of uglyif
statements. If you want to see the behavior I propose implemented, some guidance on how to fix this is very welcome.In
plugin/index.js
, the plugin sends the log output trough the socket when thedone
event occurs. This is very simple but wasteful in the case when this it ends up being ignored. I don't think this is an issue but it's worth being mentioned.