UNPKG

@roots/bud-server

Version:

Development server for @roots/bud

49 lines (48 loc) 1.52 kB
import isNull from '@roots/bud-support/isNull'; import isUndefined from '@roots/bud-support/isUndefined'; /** * Overlay * * @returns Set of client script callbacks */ export const callback = () => { return new Set([hmrClient, proxyClickInterceptor]); }; /** * Proxy click interceptor * * @param app - Bud instance * @returns string */ export const proxyClickInterceptor = (app) => { if (!app.hooks.filter(`dev.middleware.enabled`, []).includes(`proxy`)) return false; const params = new URLSearchParams({ replace: `/`, search: app.hooks.filter(`dev.middleware.proxy.options.target`, new URL(`http://0.0.0.0`))?.href, }); return `@roots/bud-client/lib/intercept/proxy-click-interceptor.js?${params.toString()}`; }; /** * Client * * @param app - Bud instance * @returns string */ export const hmrClient = (app) => { if (app.context.hot === false) return false; const params = new URLSearchParams({ indicator: isUndefined(app.context.indicator) || isNull(app.context.indicator) ? `true` : app.context.indicator.toString(), name: app.label, overlay: isUndefined(app.context.overlay) || isNull(app.context.overlay) ? `true` : app.context.overlay.toString(), reload: isUndefined(app.context.reload) || isNull(app.context.reload) ? `true` : app.context.reload.toString(), }); return `@roots/bud-client/lib/hot/index.js?${params.toString()}`; };