Build-Time Pre-Rendering Turns a Vue3 SPA into 21 Crawler-Friendly Pages
SPAs that return the same index.html for every route leave crawlers with a single homepage and a sea of duplicate URLs, making them invisible in search and to AI bots. Build-time pre-rendering fixes this without adding a Node service or running headless browsers in CI, giving Vue3+Vite sites a cheap path to real discoverability.
Client-side-only SPAs that rely on a single index.html fallback are nearly invisible to search engines and AI crawlers. Every route returns the homepage's head and body, soft 404s multiply, and the site ends up with a handful of old URLs in `site:` queries. This article documents a build-time pre-rendering solution that treats Vite's dist/index.html as a template and derives 21 static pages from it, each with its own TDK, JSON-LD structured data, and a static snapshot of the body content.
The implementation uses a Vite plugin hooked into writeBundle. It strips existing head tags in a specific order (comments first, then title and meta), writes dedicated per-page tags, injects a schema.org @graph containing Organization, Service, BreadcrumbList, and FAQPage, and drops a plain-HTML body snapshot into the #app mount point. The result is a folder structure like /bid/zhejiang/index.html served directly by nginx, with no server-side rendering, no headless browser, and zero runtime dependencies.
The author also generates sitemap.xml and a separate Chinese-only sitemap-zh.xml, verifies that GPTBot, ClaudeBot, PerplexityBot, and Bytespider all fetch the static pages successfully, and lists five pitfalls they hit, including double `<title>` tags, premature script closing from unescaped `<` in JSON-LD, canonical URL mismatches from missing trailing slashes, and soft 404s from the catch-all route. A final warning frames pre-rendering as legitimate only when the static snapshot matches the real rendered content exactly, otherwise it becomes cloaking and risks search engine penalties.
The choice to use regex for head tag stripping instead of a DOM parser is a pragmatic trade-off that works only if the index.html template stays stable and comments are kept clean of tag-like text; it shifts risk from build time to team discipline.
Converting SEO from a runtime problem to a build-time problem fits naturally with fully decoupled SPA + API architectures, making it a no-cost win compared to SSR or headless browser approaches.
The pre-rendered snapshot must match what Vue actually renders, otherwise the technique crosses into cloaking and invites search penalties, so the snapshot is generated from the same data rather than hand-written.