UNPKG

@fjell/docs-template

Version:

Shared documentation template for Fjell projects

59 lines (58 loc) 1.52 kB
// src/config/index.ts import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { readFileSync } from "fs"; import { resolve } from "path"; var createDocsViteConfig = (options = {}) => { const { basePath = "/", port = 3e3, plugins = [], packageJsonPath = "../package.json", defineVars = {} } = options; let version = "1.0.0"; try { const packageJson = JSON.parse( readFileSync(resolve(process.cwd(), packageJsonPath), "utf-8") ); version = packageJson.version; } catch { console.warn("Could not read package.json for version, using default"); } const versionInjectionPlugin = () => { return { name: "version-injection", transformIndexHtml(html) { return html.replace( "<head>", `<head> <script>window.__APP_VERSION__ = "${version}";</script>` ); } }; }; return defineConfig({ plugins: [react(), versionInjectionPlugin(), ...plugins], base: basePath, build: { outDir: "dist", emptyOutDir: true, assetsDir: "" // Keep assets in root instead of assets/ subdirectory }, server: { port }, define: { // Inject the version at build time so it's available in the deployed static files // This is used by DocsApp when config.version.source is 'package.json' __APP_VERSION__: JSON.stringify(version), ...defineVars } }); }; export { createDocsViteConfig }; //# sourceMappingURL=index.js.map