This template can be deployed to various hosting platforms. Choose the one that best fits your needs.
The easiest way to deploy is using Vercel:
npm install -g vercel
vercel
Create a vercel.json file:
{
"buildCommand": "npm run build",
"outputDirectory": ".output/public",
"framework": "nuxtjs"
}
npm run build.output/public# Install Netlify CLI
npm install -g netlify-cli
# Deploy
netlify deploy --prod
Create a netlify.toml file:
[build]
command = "npm run build"
publish = ".output/public"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
npm run build.output/publicNODE_VERSION to 18 or higher# Install Wrangler
npm install -g wrangler
# Deploy
wrangler pages deploy .output/public
Create a Dockerfile:
FROM node:18-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Build application
RUN npm run build
# Expose port
EXPOSE 3000
# Start application
CMD ["node", ".output/server/index.mjs"]
# Build image
docker build -t my-app .
# Run container
docker run -p 3000:3000 my-app
Create a docker-compose.yml:
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
restart: unless-stopped
npm run generate
This creates a .output/public directory with static files.
Upload the .output/public directory to:
Create a .env file:
NUXT_PUBLIC_API_URL=https://api.example.com
DATABASE_URL=postgresql://...
Vercel:
vercel env add NUXT_PUBLIC_API_URL
Netlify:
netlify env:set NUXT_PUBLIC_API_URL "https://api.example.com"
Cloudflare: Set in the Pages dashboard under Settings > Environment variables
// nuxt.config.ts
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/']
},
compressPublicAssets: true
}
})
Use a CDN for static assets:
export default defineNuxtConfig({
app: {
cdnURL: 'https://cdn.example.com'
}
})
Install Sentry:
npm install @sentry/nuxt
Configure in nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@sentry/nuxt/module'],
sentry: {
dsn: process.env.SENTRY_DSN
}
})
Add analytics in app.vue:
<script setup lang="ts">
useHead({
script: [
{
src: 'https://analytics.example.com/script.js',
defer: true
}
]
})
</script>
Create .github/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy
run: npm run deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
Check Node.js version:
node --version # Should be 18 or higher
Clear cache and rebuild:
rm -rf node_modules .nuxt
npm install
npm run build
Enable debug mode:
DEBUG=nuxt:* npm run dev
Check server logs in your hosting platform's dashboard.
npm run build && npm run preview.env files to version control. Use platform-specific environment variable management.