120
loading...
This website collects cookies to deliver better user experience
vercel.json
file at the root of your Angular Universal project with YOUR_PROJECT_NAME:{
"version": 2,
"public": true,
"name": "test-universal",
"rewrites": [
{ "source": "/(.*)", "destination": "/api" }
],
"functions": {
"api/index.js": {
"includeFiles": "dist/YOUR_PROJECT_NAME/browser/**"
}
}
}
api/
folder. You must also select which files to give your script access to with includeFiles
.scripts.build
to scripts.build-dev
in package.json
. Vercel runs npm run build
automatically, with only access for the browser. We do not need that in this case.scripts.vercel-build
with the value npm run build:ssr
. This is run specifically within the serverless function to give you access to all your files and scripts.{
"name": "test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build-dev": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"dev:ssr": "ng run test:serve-ssr",
"serve:ssr": "node dist/test/server/main.js",
"build:ssr": "ng build && ng run test:server",
"prerender": "ng run test:prerender",
"vercel-build": "npm run build:ssr"
},
...
api/index.js
. All scripts in the api
directory are automatically used as serverless functions.const server = require('../dist/YOUR_PROJECT_NAME/server/main');
module.exports = server.app();
New Project
, and select your GitHub Repository.