fix(web/m7-363): vite plugin fails build if anchors drift
This commit is contained in:
@@ -13,6 +13,9 @@ const tokensPlugin = {
|
||||
// rendered index.html so the runtime Go server can substitute per-
|
||||
// instance branding. In dev (`vite dev`), the marker stays as a
|
||||
// comment and the SPA falls back to the literal app.html title.
|
||||
// `enforce: 'post'` ensures this runs after SvelteKit's own
|
||||
// transformIndexHtml so %sveltekit.head% is already expanded into
|
||||
// hydration markup before our anchors are rewritten.
|
||||
const injectGoTokensPlugin = {
|
||||
name: 'minstrel-inject-go-tokens',
|
||||
apply: 'build' as const,
|
||||
@@ -29,6 +32,17 @@ const injectGoTokensPlugin = {
|
||||
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#14171A">
|
||||
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#F8F5EE">
|
||||
<script>window.__MINSTREL__ = { appName: "{{ .AppName }}", description: "{{ .Description }}" };</script>`;
|
||||
|
||||
// Fail loudly if either anchor drifts. A silent .replace() no-op
|
||||
// would ship a build with un-substituted Go template tokens missing,
|
||||
// and the runtime brand override would silently break — exactly the
|
||||
// class of regression a build-time plugin should catch.
|
||||
if (!html.includes('<title>Minstrel</title>')) {
|
||||
throw new Error('minstrel-inject-go-tokens: <title>Minstrel</title> anchor missing from rendered index.html');
|
||||
}
|
||||
if (!html.includes('<!-- MINSTREL_TOKENS -->')) {
|
||||
throw new Error('minstrel-inject-go-tokens: <!-- MINSTREL_TOKENS --> anchor missing from app.html');
|
||||
}
|
||||
return html
|
||||
.replace('<title>Minstrel</title>', titleTag)
|
||||
.replace('<!-- MINSTREL_TOKENS -->', headBlock);
|
||||
|
||||
Reference in New Issue
Block a user