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.
Deploying the Project
- Create analog
- Nx
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.
In the build settings of your Netlify project on the web UI, do the following.
- Set the build command to
nx build [your-project-name]
- Set the publish directory to
dist/[your-project-name]/analog/public
to deploy the static assets - Set the functions directory to
dist/[your-project-name]/analog
to deploy the server.
You can also configure this by putting a netlify.toml
at the root of your repository. Below is an example config.
# replace "my-analog-app" with the name of the app you want to deploy
[build]
command = "nx build my-analog-app"
publish = "dist/my-analog-app/analog/public"
functions = "dist/my-analog-app/analog"
Vercel
Analog supports deploying on Vercel with no additional configuration.
Deploying the Project
- Create analog
- Nx
By default, when deploying to Vercel, the build preset is handled automatically.
-
Create a new project and select the repository that contains your code.
-
Click 'Deploy'.
And that's it!
In order to make it work with Nx, we need to define the specific app we want to build. There are several ways to do this, and you can choose one of the following methods (replace <app> with your app name):
- Define the
defaultProject
in yournx.json
{
"defaultProject": "<app>"
}
- Create a
vercel.json
file in the root of your project and define thebuildCommand
:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"buildCommand": "nx build <app>"
}
- Define the
buildCommand
in yourpackage.json
:
{
"scripts": {
"build": "nx build <app>"
}
}
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.
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_PRESET
environment variable tovercel
. - Set the preset in the
vite.config.ts
file:
import { defineConfig } from 'vite';
import analog from '@analogjs/platform';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
/// ...other config
plugins: [
analog({
nitro: {
preset: 'vercel',
},
}),
],
}));
Cloudflare Pages
Analog supports deploying to Cloudflare Pages with minimal configuration.
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 build
as theBuild Command
. - Enter
dist/analog/public
as 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.
Nx and Cloudlfare
For Nx workspaces, the build output is under the app name. Update the Build output directory
accordingly.
For example:
Build output directory: dist/[your-project-name]/analog/public
To test the build locally, run the following command:
BUILD_PRESET=cloudflare-pages npx nx build [your-project-name]
Running the application locally using Wrangler
You can also preview the application running on Cloudflare locally:
- Set the environment variable
BUILD_PRESET
tocloudflare-pages
before running the build
BUILD_PRESET=cloudflare-pages npm run build
- Use the
wrangler
CLI 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
Login to Firebase and select the Hosting and Functions options as shown below:
firebase login
firebase init
◉ Functions: Configure a Cloud Functions directory and its files
◉ Hosting: Configure files for Firebase Hosting and (optionally) set up
GitHub Action deploys
Unless you have an existing Firebase project, select Create a new project to continue. Firebase will provision a new project and provide the URL to access the web console to manage it.
Once your project is created, select TypeScript as the language to use to write Cloud Functions. Proceed with accepting the default parameters by pressing Enter.
When prompted for the public directory, enter dist/analog/public
.
In the next step, take the default option, N, on whether to configure as a single-page app. This is important! Do not configure your project as a single-page app.
After setup completes, ensure that the following properties are configured correctly in your firebase.json
file. This ensures server-side rendering will work correctly with 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.
Firebase functions
Ensure that you set up Firebase functions as described in the previous section. Next, you must configure Nitro correctly for Firebase Cloud Functions to work.
In vite.config.ts
update the nitro
property with the configuration options that fit your needs, like your Node.js version and preferred region.
nitro: {
preset: 'firebase',
firebase: {
nodeVersion: '20',
gen: 2,
httpsOptions: {
region: 'us-east1',
maxInstances: 100,
},
},
},
Alternatively, multiple AnalogJS projects (/app1, /app2) in a single Firebase Hosting site
This leverages cloud run services to host AnalogJS projects and uses rewrite rules for forwarding traffic from firebase to cloud run.
Deploying with a custom URL prefix.
{
"hosting": [
{
"site": "<your_project_id>",
"public": "public",
"cleanUrls": true,
"rewrites": [
{
"source": "/app1",
"run": {
"serviceId": "app1",
"region": "us-central1",
"pinTag": false
}
},
{
"source": "/app1/**",
"run": {
"serviceId": "app1",
"region": "us-central1",
"pinTag": false
}
}
]
}
]
}
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
Firebase Warnings
When configuring or deploying Firebase you may see warnings like:
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: undefined,
npm WARN EBADENGINE required: { node: '18' },
npm WARN EBADENGINE current: { node: 'v20.11.0', npm: '10.2.4' }
npm WARN EBADENGINE }
⚠ functions: Couldn't find firebase-functions package in your source code. Have you run 'npm install'?
These are benign errors and can be ignored, so long as you make sure your environment configuration matches Nitro
.
Render.com
Analog supports deploying on Render with minimal configuration.