UNPKG

vite-plugin-office-addin

Version:

Office Add-ins development using Vite.

34 lines 1.28 kB
import { loadEnv } from 'vite'; import fs from 'fs'; import path from 'path'; export default function officeManifest(options) { const manifestFile = options?.path ?? 'manifest.xml'; let viteConfig; let env; return { name: 'office-addin:manifest', configResolved(resolvedConfig) { viteConfig = resolvedConfig; env = loadEnv(viteConfig.mode, process.cwd(), 'ADDIN'); }, generateBundle() { const manifestPath = path.resolve(viteConfig.root, manifestFile); if (!fs.existsSync(manifestPath)) { viteConfig.logger.warn(`The manifest.xml file does not exist at path: '${manifestPath}'`); return; } const devUrl = options?.devUrl || env['ADDIN_DEV_URL']; const prodUrl = options?.prodUrl || env['ADDIN_PROD_URL']; let content = fs.readFileSync(manifestPath, 'utf-8'); if (devUrl && devUrl != '') { content = content.replace(new RegExp(devUrl, "g"), prodUrl); } this.emitFile({ type: 'asset', fileName: path.basename(manifestPath), source: content }); }, }; } //# sourceMappingURL=index.js.map