Async options for BrowserSync config
zachleat opened this issue · comments
Some discussion with @Holben888 prompted the Slinkity/Vite need to do some async work to generate middleware options for browsersync.
https://github.com/slinkity/slinkity/blob/main/src/plugin/index.js#L101-L125
Note server = await viteSSR.createServer()
Because async config init is a very hefty task (no async in class constructors), we thought perhaps a more specialized case might be warranted here, because the browsersync init happens so late in the order of operations.
Note sure what that looks like yet.
Eleventy->watch is already async
Line 798 in 5020390
Eleventy->serve is not yet async
Line 886 in 5020390
cmd.js
Line 113 in 5020390
Did some initial investigation here! It seem we can't safely resolve async configs from the user config side of things, since that opens a huge "async everything" can of worms. However, it is safe to resolve async configs inside async-ready functions like elev.serve
.
We'll likely need to touch 2 functions:
Line 54 in 1ea3a90
Adding an await
before the Object.assign
statement
Line 136 in 1ea3a90
Adding an await
before the this.getOptions
call
There's just 1 snag left to fix: merging browsersync configs. This is currently handled from the user-facing setBrowserSyncConfig
, so it could only work when options
is synchronous 😬
Lines 676 to 682 in 1ea3a90
We'll likely need to move merge
into the getOptions
call mentioned earlier. We'll also need to change UserConfig.browserSyncConfig
to an array of configs so we can delay merging until later (when it's safe to perform async operations).
Will check back on this, but it seems doable!
Should be good to close with new 11ty 2.0 server "setup" option!
Indeed setup
is async-friendly! https://github.com/11ty/eleventy/blob/0611393b62c789cb805a4ce9e62e3dea0086b492/src/EleventyServe.js