UNPKG

msoffice-addin

Version:

Microsoft office addin module for Nuxt abd vite

33 lines (32 loc) 1.04 kB
import { defineNitroPlugin } from "nitropack/runtime"; import context from "#office-addin-content"; export default defineNitroPlugin(async (nitro) => { const { manifests, options } = context; if (!options || !options.manifests.length) return; nitro.hooks.hook("request", (event) => { const manifest = manifests.find((i) => i.route === event.path); if (manifest) { const headers = { "content-type": "text/xml" }; event.respondWith( new Response(manifest.content, { headers }) ); } }); nitro.hooks.hook("render:html", (html, context2) => { const { injectOfficeJS = [] } = options; const currentPath = context2.event.path; if (!injectOfficeJS.length) return; const matches = injectOfficeJS.some( (entry) => entry instanceof RegExp ? entry.test(currentPath) : entry === currentPath ); if (matches) { html.head.push( `<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"><\/script>` ); } }); });