(options?: Options)
| 318 | * @since 4.2.0 |
| 319 | */ |
| 320 | export const plugin = (options?: Options): Plugin => { |
| 321 | const url = DevToolsServer.url(options) |
| 322 | const size = Math.max(1, options?.size ?? 1_000) |
| 323 | const fields = options?.fields |
| 324 | const hot = options?.hot !== false |
| 325 | const overlay = options?.overlay !== false |
| 326 | const overlayOptions: OverlayOptions = typeof options?.overlay === "object" |
| 327 | ? options.overlay |
| 328 | : {} |
| 329 | const workbench = options?.workbench |
| 330 | let base = "/" |
| 331 | let bound = Promise.resolve(false) |
| 332 | let partial = false |
| 333 | return { |
| 334 | name: "effect-ui-devtools", |
| 335 | apply: (_, env) => |
| 336 | env.command === "serve" && env.isPreview !== true && |
| 337 | !("VITEST" in process.env), |
| 338 | config: (config) => |
| 339 | hot && config.experimental?.hmrPartialAccept === undefined |
| 340 | ? { experimental: { hmrPartialAccept: true } } |
| 341 | : undefined, |
| 342 | configResolved: (config) => { |
| 343 | partial = hot && config.experimental?.hmrPartialAccept === true |
| 344 | base = config.base ?? "/" |
| 345 | }, |
| 346 | resolveId: (id) => |
| 347 | hot && id === hotId |
| 348 | ? resolvedHotId |
| 349 | : overlay && id === devToolsId |
| 350 | ? resolvedDevToolsId |
| 351 | : workbench !== undefined && id === workbenchId |
| 352 | ? resolvedWorkbenchId |
| 353 | : undefined, |
| 354 | load: (id) => |
| 355 | id === resolvedHotId |
| 356 | ? hotClient |
| 357 | : id === resolvedDevToolsId && overlay |
| 358 | ? devToolsClient( |
| 359 | { ...overlayOptions, fields }, |
| 360 | workbench === undefined ? undefined : base |
| 361 | ) |
| 362 | : id === resolvedWorkbenchId && workbench !== undefined |
| 363 | ? workbenchClient(workbench) |
| 364 | : undefined, |
| 365 | transform(code, id, options) { |
| 366 | if (!partial || options?.ssr === true) return undefined |
| 367 | const program = programOf(this, code, id) |
| 368 | if (program === undefined) return undefined |
| 369 | const found = hotExports.find(program as never) |
| 370 | if (found.length === 0) return undefined |
| 371 | return { code: code + hotExports.footer(found), map: null } |
| 372 | }, |
| 373 | configureServer: (server) => { |
| 374 | // Registered here, not in a returned hook, so it runs before the app's |
| 375 | // catch-all, such as HtmlServerVite's. |
| 376 | if (workbench !== undefined) { |
| 377 | server.middlewares.use((req, res, next) => { |
nothing calls this directly
no test coverage detected