What Is New in Nuxt 2
| Category | Highlights |
|---|---|
| New Features | Universal rendering (SSR, SPA, static generation), file-system routing, automatic code splitting per page, built-in webpack & Babel, hot module reloading, server-middleware mode, programmatic API (Nuxt & Builder classes) |
| Improvements | Configurable via nuxt.config.js, static file serving from ./static, layout system via ./layouts, middleware support, separate build and start commands for production, CLI starter templates |
How does Nuxt 2 enable universal rendering modes?
Nuxt 2 lets you choose between server-side rendering, single-page application, or static site generation at build time.
In practice you set mode or target in nuxt.config.js and Nuxt configures webpack accordingly. This matters if you need SEO-friendly pages (SSR) or want to pre-render everything for a CDN (static).
// nuxt.config.js
export default {
target: 'static', // or 'server' for SSR
ssr: true // false for SPA mode
}
What is the file-system based routing and layout system in Nuxt 2?
Every .vue file placed in the pages/ directory automatically becomes a route, and any .vue file in layouts/ can be applied via the layout property.
This eliminates manual router configuration and keeps route definitions close to the component code, which speeds up onboarding for new team members.
// pages/about.vue
<template>
<div>About us</div>
</template>
// layouts/default.vue
<template>
<div>
<Header />
<nuxt />
<Footer />
</div>
</template>
How can I integrate Nuxt 2 as middleware in a custom Node server?
You can mount nuxt.render as the last middleware in an Express, Koa, or any Connect-compatible server.
This matters when you need custom API routes, authentication layers, or other server-side logic before handing over to Nuxt for rendering.
const express = require('express')
const { Nuxt } = require('nuxt')
const config = require('./nuxt.config.js')
const nuxt = new Nuxt(config)
const app = express()
app.use('/api', apiRouter) // your custom API
app.use(nuxt.render) // Nuxt handles everything else
app.listen(3000)
How do I build and start a Nuxt 2 application for production?
Run nuxt build to compile assets and generate the .nuxt directory, then launch the server with nuxt start.
This separation lets CI pipelines cache the build step and makes scaling easier because the runtime only serves pre-compiled files.
# Build step
nuxt build
# Runtime
nuxt start
How can I use Nuxt 2 programmatically for custom rendering?
Import the Nuxt and Builder classes, instantiate them with your config, and call renderRoute or render as needed.
This is useful for serverless functions, testing, or generating HTML snapshots for SEO.
const { Nuxt, Builder } = require('nuxt')
const config = require('./nuxt.config.js')
config.dev = false
const nuxt = new Nuxt(config)
new Builder(nuxt).build().then(() => {
return nuxt.renderRoute('/about')
}).then(({ html }) => {
console.log(html)
})
Frequently Asked Questions
Can I switch from SSR to SPA without rewriting my pages?
Yes, just change the ssr flag in nuxt.config.js and Nuxt will serve the same components as a client-only app.
Do I need to install webpack manually?
No, Nuxt bundles webpack and Babel out of the box, so you can focus on your code.
Is the static folder still served at the root URL?
Yes, any file placed in ./static is automatically mapped to /.
How do I add a global middleware that runs before every route?
Create a file in the middleware directory and reference it in nuxt.config.js under router.middleware.
What command should I run to generate a production-ready build?
Run nuxt build then nuxt start to launch the compiled application.
Can I render a single route from a serverless function?
Yes, use nuxt.renderRoute('/path', context) and return the html string from the function.