-
Notifications
You must be signed in to change notification settings - Fork 3
CLI only shows assets emitted for initial build, not subsequent watcher-trigger builds #9
Comments
Hey @markfinger , I'm not sure if this is related to the issue that you're describing, but it looks like the callback passed into Is there a way to have the callback invoked multiple times? |
Yes, in principle, but it becomes a bit problematic once things are run in a worker process. For context, most of the system was built to work on a request/response cycle, eg: refreshing a browser and requesting the current state of the build. The CLI was a bit a hack job that I needed on a particular project. Hmm, there are lower layers that expose that sort of an interface, so we'd need to either expose them higher up, or just poke around the currently running |
If things are running in a worker process, we'd need to expand the amount of messages that the workers send back to the parent. |
Hmm, a hack to get around the architectural limitations would be polling via a |
Ah ok. Is the semantic of a request a single invocation of the compiler (i.e., compiler.run(..)), where compiler is a webpack instance with a particular options object? I'm also assuming that at most one worker deals with a single request. In that case, would it be possible to do the following:
|
Requests should be considered as an invocation of webpack-build. Incoming requests are matched to compilers by serialising the options object, hashing it, and then using that hash as a key. When a request is passed in to webpack-build it looks to see if there is a compiler already running that matches the request and passes the request down to it. If there is no matching compiler, it spawns a new one and then passes the request to it. If worker processes are available, it looks to see if there is a worker that has previously handled the request, then sends it to that process. If no worker has handled it, it picks the next available one and requests it to start handling it. Jobs are assigned to workers in sequential fashion, so it's possible for workers to handle multiple compilers. Internally references are maintained to the compilers and little state machines (the The workers have a messaging interface built in, so it should be easy enough to add another message type, if needed. This might be the best point to intercept and pass a message up: https://github.com/markfinger/webpack-build/blob/master/src/wrappers/Wrapper.js#L218-L228 Here's an example of conditionally sending messages if the code is running in a worker: https://github.com/markfinger/webpack-build/blob/master/src/hmr/index.js#L22-L27 This is where the parent process receives messages: https://github.com/markfinger/webpack-build/blob/master/src/workers/Worker.js#L112-L147 Also, not sure if it's of use, workers share the IO of the parent process, so you can If you invoke your process with |
Something along these lines would be incredibly useful to me — basically a way to listen for a Maybe this is doable already, though haven't been able to figure it out if so... |
@imathews you should be able to just invoke the wrapper and it'll execute your callback when the build's done. // ...
var webpackBuild = require('webpack-build');
// ...
// assuming you wanted it in a middleware
app.use(function(req, res, next) {
webpackBuild({
// ...
}, function(err, data) {
if (err) return res.status(500).end('Build error: ' + err.stack);
// Attach the data to the response
res.locals.build = data;
// Assuming you define `staticUrl` and `staticRoot`, the `urls` prop should contain
// urls grouped by entrys
console.log(data.urls); // urls
next();
});
}); This package was designed to handle that exact scenario - unfortunately, to the detriment of other use cases :( |
@markfinger Thanks!! This is exactly what I needed, working perfectly. For what it's worth, might be good to throw an example to this effect in the README... definitely wasn't obvious to me. (I was calling the build function once, rather than every time a request was made). Cheers. |
From memory, the compiler wrapper gets returned by the
build
function. So something likeThe text was updated successfully, but these errors were encountered: