Static export
By default puzzle build makes a single-page app: one index.html, one app.js, and the router draws every page in the browser. puzzle build --static makes a true static site instead. Every route becomes its own index.html, with the page's markup already in it, plus a small script that brings that page's components to life.
Search engines and link previews read the HTML directly, and the page shows before any JavaScript runs. Set output: 'static' in puzzle.config.js to make it the default.
The rules that come with it
data()andbeforeMountrun in Node at build time. Guard anything that only exists in a browser, such aswindow,documentorlocalStorage, and put DOM work inmounted().beforeMountnever runs in the browser on a static page. Whatever it puts in the store is written into each page instead.- A
:paramroute is prerendered once perstaticPathsentry; without one it is skipped with a warning. - Navigation is a normal page load. There is no router in the browser.
The build warns about one of these on the scaffold: the shout function lives in app.js, which static pages never load. Moving it to app/formatters.js fixes it.
This site is built this way. Every lesson of this tutorial is a static page made by puzzle build --static.
Chapter 3 goes back to a single-page app, where :param routes are fine.