* Build optimized assets for your app. By default this will create * a production build. * * This can also be used for testing to apply a snapshot to a particular * code App instance. * * @example Testing * ```ts * const builder = new Builder(); * const applySnapsho
(
options?: {
mode?: ResolvedBuildConfig["mode"];
snapshot?: "disk" | "memory";
},
)
| 253 | * @returns Apply a snapshot to a particular {@linkcode App} instance. |
| 254 | */ |
| 255 | async build( |
| 256 | options?: { |
| 257 | mode?: ResolvedBuildConfig["mode"]; |
| 258 | snapshot?: "disk" | "memory"; |
| 259 | }, |
| 260 | ): Promise<(app: App<State>) => void> { |
| 261 | this.config.mode = options?.mode ?? "production"; |
| 262 | |
| 263 | await this.#crawlFsItems(); |
| 264 | |
| 265 | const buildCache = options?.snapshot === "memory" |
| 266 | ? new MemoryBuildCache( |
| 267 | this.config, |
| 268 | this.#fsRoutes, |
| 269 | this.#transformer, |
| 270 | ) |
| 271 | : new DiskBuildCache( |
| 272 | this.config, |
| 273 | this.#fsRoutes, |
| 274 | this.#transformer, |
| 275 | ); |
| 276 | |
| 277 | await this.#build(buildCache, this.config.mode === "development"); |
| 278 | await buildCache.prepare(); |
| 279 | |
| 280 | return (app) => { |
| 281 | setBuildCache(app, buildCache, app.config.mode); |
| 282 | }; |
| 283 | } |
| 284 | |
| 285 | async #crawlFsItems() { |
| 286 | const { islands, routes } = await crawlFsItem( |
no test coverage detected