| | |
| | | } |
| | | |
| | | function joinScripts(scripts: string[]): string { |
| | | return scripts.join("\n") |
| | | // wrap with iife to prevent scope collision |
| | | return scripts.map(script => `(function () {${script}})();`).join("\n") |
| | | } |
| | | |
| | | export function emitComponentResources(cfg: GlobalConfiguration, resources: StaticResources, plugins: PluginTypes, emit: EmitCallback) { |
| | |
| | | componentResources.afterDOMLoaded.push(spaRouterScript) |
| | | } else { |
| | | componentResources.afterDOMLoaded.push(` |
| | | window.spaNavigate = (url, _) => window.location.assign(url) |
| | | const event = new CustomEvent("nav", { detail: { slug: document.body.dataset.slug } }) |
| | | document.dispatchEvent(event)` |
| | | ) |
| | |
| | | } |
| | | |
| | | for (const transformer of plugins.transformers) { |
| | | const res = transformer.externalResources |
| | | const res = transformer.externalResources ? transformer.externalResources() : {} |
| | | if (res?.js) { |
| | | staticResources.js = staticResources.js.concat(res.js) |
| | | } |