Providers
Analog supports deployment to many providers with little or no additional configuration using Nitro as its underlying server engine. You can find more providers in the Nitro deployment docs.
Netlify
Analog supports deploying on Netlify with minimal configuration.
In the build settings of your Netlify project, set the Publish directory to dist/analog/public to deploy the static assets and the Functions directory to dist/analog to deploy the server.
Vercel
Analog supports deploying on Vercel with no additional configuration.
Deploying the Project
- Create analog
- Nx
Create a new project and select the repository that contains your code.
Click 'Deploy'.
And that's it!
- Define the
defaultProjectin yournx.json
{
"defaultProject": "<app>"
}
- Create a
vercel.jsonfile in the root of your project and define thebuildCommand:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"buildCommand": "nx build <app>"
}
- Define the
buildCommandin yourpackage.json:
{
"scripts": {
"build": "nx build <app>"
}
}
Setting the Preset Manually
There might be a case where Vercel doesn't load the preset automatically. In that case, you can do one of the following.
- Set the
BUILD_PRESETenvironment variable tovercel. - Set the preset in the
vite.config.tsfile:
import { defineConfig } from 'vite';
import analog from '@analogjs/platform';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
/// ...other config
plugins: [
analog({
nitro: {
preset: 'vercel',
},
}),
],
}));
Nx and Vercel
When using Nx and reusing the build cache on the Vercel build platform, there is a possibility that the cache is reused if you have built it locally. This can lead to the output being placed in the wrong location. To resolve this issue, you can use the preset in the vite.config.ts file as a workaround.
Cloudflare Pages and Workers
Analog supports deploying to Cloudflare pages and workers with some configuration.
Updating the Server Entry Point
The main.server.ts file should be updated to provide the full URL and the APP_BASE_HREF token on the server for Cloudflare support.
import { renderApplication } from '@angular/platform-server';
import { APP_BASE_HREF } from '@angular/common';
/// imports and bootstrap code ...
export default async function render(url: string, document: string) {
// set the base href
const baseHref = process.env['CF_PAGES_URL'] ?? `http://localhost:8888`;
// Use the full URL and provide the APP_BASE_HREF
const html = await renderApplication(bootstrap, {
document,
url: `${baseHref}${url}`,
platformProviders: [{ provide: APP_BASE_HREF, useValue: baseHref }],
});
return html;
}
Setting the Output Directory
For the Cloudflare deployment, set the output as below. This combines the static assets, along with the Cloudflare worker in the same output directory.
import { defineConfig } from 'vite';
import analog from '@analogjs/platform';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
/// ...other config
plugins: [
analog({
nitro: {
output: {
dir: './dist/analog/public',
serverDir: './dist/analog/public',
},
},
}),
],
}));
Deploying to Cloudflare
To connect your repository and deploy automatically to Cloudflare:
- Log in to the Cloudflare dashboard and select your account.
- In Account Home, select Workers & Pages.
- Select Create application > Pages > Connect to Git.
- Enter
npm run buildas theBuild Command. - Enter
dist/analog/publicas theBuild output directory. - Leave the other default settings, click
Save and Deploy.
The application deploys to Cloudflare's network on each push to the repository.
Running the application locally using Wrangler
You can also preview the application running on Cloudflare locally:
- Set the environment variable
BUILD_PRESETtocloudflare-pagesbefore running the build
BUILD_PRESET=cloudflare-pages npm run build
- Use the
wranglerCLI to run the application locally
npx wrangler pages dev ./dist/analog/public
Firebase
Analog supports Firebase Hosting with Cloud Functions out of the box.
See a Sample Repo with Firebase configured
Note: You need to be on the Blaze plan to use Analog with Cloud Functions.
If you don't already have a firebase.json in your root directory, Analog will create one the first time you run it. In this file, you will need to replace <your_project_id> with the ID of your Firebase project.
This file should then be committed to version control. You can also create a .firebaserc file if you don't want to manually pass your project ID to your firebase commands (with --project <your_project_id>):
{
"projects": {
"default": "<your_project_id>"
}
}
Then, just add Firebase dependencies to your project:
npm install -D firebase-admin firebase-functions firebase-functions-test
Using Firebase CLI
If prefer to set up your project with the Firebase CLI, which will fetch your project ID for you, add required dependencies (see above) and even set up automated deployments with GitHub Actions.
Install Firebase CLI globally
npm install -g firebase-tools
Note: You need to be on ^11.18.0 to deploy a nodejs18 function.
Initialize your Firebase project
firebase login
firebase init hosting
When prompted, enter dist/analog/public as the public directory.
In the next step, do not configure your project as a single-page app.
After setup completes, add the following to your firebase.json to enable server rendering in Cloud Functions:
{
"functions": { "source": "dist/analog/server" },
"hosting": [
{
"site": "<your_project_id>",
"public": "dist/analog/public",
"cleanUrls": true,
"rewrites": [{ "source": "**", "function": "server" }]
}
]
}
You can find more details in the Firebase documentation.
Local preview
You can preview a local version of your site to test things out without deploying.
BUILD_PRESET=firebase npm run build
firebase emulators:start
Deploy to Firebase Hosting using the CLI
To deploy to Firebase Hosting, run the firebase deploy command.
BUILD_PRESET=firebase npm run build
firebase deploy
Render.com
Analog supports deploying on Render with minimal configuration.
Web Service Deployment
Create a new Web Service and select the repository that contains your code.
Ensure the 'Node' environment is selected.
Specify your Node version for Render to use (v18.13.0 or higher recommended) - Render by default uses Node 14, which fails to correctly build an Analog site
Depending on your package manager, set the build command to
yarn && yarn build,npm install && npm run build, orpnpm i --shamefully-hoist && pnpm build.Update the start command to
node dist/analog/server/index.mjsClick 'Advanced' and add an environment variable with
BUILD_PRESETset torender-com.Click 'Create Web Service'.
Static Site Deployment
If using Analog to pre-render static content, you can deploy a static site on Render with minimal configuration
Create a new Static Site and select the repository that contains your code.
Depending on your package manager, set the build command to
yarn && yarn build,npm install && npm run build, orpnpm i --shamefully-hoist && pnpm build..Set the publish directory to the
publicdirectory inside of thedistbuild directory (e.g.dist/analog/public)Click 'Create Static Site'
Edgio
Analog supports deploying on Edgio with minimal configuration.
- Install the Edgio CLI:
npm i -g @edgio/cli
- In your project's directory, initialize Edgio:
edgio init --connector=@edgio/analogjs
- Deploy To Edgio
edgio deploy