0
0
Vueframework~10 mins

Static site generation with Nuxt in Vue - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Static site generation with Nuxt
Write Vue components and pages
Configure Nuxt for static generation
Run 'nuxt generate' command
Nuxt builds app and pre-renders pages
Static HTML, CSS, JS files created
Deploy static files to web server or CDN
User requests page -> static file served instantly
This flow shows how Nuxt takes your Vue app, pre-builds all pages into static files, and then serves them fast without a server.
Execution Sample
Vue
export default {
  target: 'static',
  generate: {
    routes: ['/', '/about', '/contact']
  }
}
This config tells Nuxt to generate a static site and pre-build the /about and /contact pages.
Execution Table
StepActionInput/ConfigProcessOutput
1Start Nuxt generatetarget: 'static'Nuxt reads configReady to build static site
2Scan pages folderPages: index.vue, about.vue, contact.vueIdentify routesRoutes: '/', '/about', '/contact'
3Pre-render '/' pageindex.vueRender to HTMLindex.html created
4Pre-render '/about' pageabout.vueRender to HTMLabout.html created
5Pre-render '/contact' pagecontact.vueRender to HTMLcontact.html created
6Copy assetsCSS, JS, imagesPrepare static filesAssets copied to dist folder
7Finish generationAll pages renderedBuild completeStatic site ready in /dist
8Deploy siteUpload /dist to serverServe static filesUsers get fast page loads
💡 All pages pre-rendered and static files generated for deployment
Variable Tracker
VariableStartAfter Step 2After Step 5Final
routes[]['/', '/about', '/contact']['/', '/about', '/contact']['/', '/about', '/contact']
generatedFiles{}{}{index.html, about.html, contact.html}{index.html, about.html, contact.html, assets}
Key Moments - 2 Insights
Why does Nuxt pre-render pages during 'generate' instead of rendering on user request?
Because static site generation builds all pages ahead of time (see steps 3-5 in execution_table), so users get fast static files without server rendering delays.
What happens if a page is missing from the routes list in the config?
Nuxt won't pre-render that page during generation (see step 2), so it won't have a static HTML file and may cause 404 errors when deployed.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what files are created after step 5?
ANo files yet
BOnly index.html
Cindex.html, about.html, contact.html
DAssets like CSS and JS
💡 Hint
Check the 'Output' column at step 5 in the execution_table
At which step does Nuxt copy CSS, JS, and images to the static folder?
AStep 3
BStep 6
CStep 2
DStep 8
💡 Hint
Look for 'Copy assets' action in the execution_table
If you add a new page 'blog.vue' but don't update routes in config, what happens?
Ablog page is not pre-rendered and missing in static files
BNuxt pre-renders blog page automatically
CNuxt throws an error and stops
Dblog page is rendered on user request dynamically
💡 Hint
Refer to key_moments about missing routes and step 2 in execution_table
Concept Snapshot
Static Site Generation with Nuxt:
- Set target: 'static' in nuxt.config.js
- Use 'nuxt generate' to pre-build pages
- Nuxt renders each page to HTML ahead of time
- Static files served fast without server
- Configure routes to include all pages
- Deploy /dist folder to any static host
Full Transcript
Static site generation with Nuxt means building your Vue app pages into static HTML files before users visit. You write your Vue components and pages, then configure Nuxt to use the 'static' target. Running 'nuxt generate' scans your pages, pre-renders each one into HTML, and copies assets like CSS and JavaScript. The result is a folder full of static files ready to deploy anywhere. When users visit, they get fast page loads because the server just sends static files without running code. Make sure to include all your pages in the routes config so Nuxt pre-renders them. This process improves speed and reliability for your website.