diff --git a/index.html b/index.html index 280ab913ff..25e84494af 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ + <%- snippets %>
diff --git a/vite.config.ts b/vite.config.ts index 263f6a20bd..8141f5b8b8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,4 +1,5 @@ /// +import fs from 'node:fs'; import { fileURLToPath, URL } from 'node:url'; import react from '@vitejs/plugin-react'; @@ -36,6 +37,11 @@ export default defineConfig({ collapseWhitespace: true, removeComments: false, }, + inject: { + data: { + snippets: readFileContents('custom/snippets.html'), + }, + }, }), react({ // Use React plugin in all *.jsx and *.tsx files @@ -88,4 +94,13 @@ export default defineConfig({ environment: 'jsdom', setupFiles: 'src/jest/test-setup.ts', }, -}); \ No newline at end of file +}); + +/** Return file as string, or return empty string if the file isn't found. */ +function readFileContents(path: string) { + try { + return fs.readFileSync(path, 'utf8'); + } catch { + return ''; + } +}