You can capture an event when a single bundle is completed. You will have access
FuseProcess that will help you to launch your application on server.
fuse.bundle("bundle2") .instructions(`~ index.ts`); .completed(proc => proc.start()) fuse.run()
Executing a bundle
completed(proc => proc.exec());
The following code will spawn a separate nodejs process once.
Start / restart
completed(proc => proc.start());
The following code will spawn a separate nodejs process, if a process is already running FuseBox will kill and spawn a new one.
completed(proc => proc.require(opts));
The following code will require a file in the same process as the fuse process instead of launching a new one.
The differences are :
- A bundle is executed in a
Promiseand its exports are available to the fuse caller :
proc.require().then(exports => void).
- A bundle has access to the same loaded libraries than the fuser, they share the same global object.
- A bundle is inspected if fuse is inspected:
node --debug fuse.jsdebugs the bundle too.
- To free the allocated resources when a bundle is restarted, there is no clean
process.killoption; it must therefore export a
closefunction, or a default that has such a function.
express bundle would look as follows:
export default app.listen(process.env.PORT);
close(bundleExport)=> Promise: A closing function.
The exports of the main file can be retrieved with
When the module is unloaded, the first of these functions is called :
- A function
close(bundleExport)=> Promisegiven as an option to
After, if the bundle has a main file,
export function close(): Promisein the bundle
- A default export who has a
If the close function returns a promise, this one will be awaited before
requiring the new version of the bundle. If it returns anything else than a
promise, the value is ignored. The
require function by itself returns a
promise that resolves to the loaded bundle main-file