> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/vitejs/vite/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying Static Sites

> Deploy your Vite application to popular platforms like Netlify, Vercel, GitHub Pages, and more

The following guides are based on some shared assumptions:

* You are using the default build output location (`dist`). This location [can be changed using `build.outDir`](/config/build-options#build-outdir), and you can extrapolate instructions from these guides in that case.
* You are using npm. You can use equivalent commands to run the scripts if you are using Yarn or other package managers.
* Vite is installed as a local dev dependency in your project, and you have setup the following npm scripts:

```json package.json theme={null}
{
  "scripts": {
    "build": "vite build",
    "preview": "vite preview"
  }
}
```

<Note>
  It is important to note that `vite preview` is intended for previewing the build locally and not meant as a production server.
</Note>

<Tip>
  These guides provide instructions for performing a static deployment of your Vite site. Vite also supports Server-Side Rendering. SSR refers to front-end frameworks that support running the same application in Node.js, pre-rendering it to HTML, and finally hydrating it on the client. Check out the [SSR Guide](/guides/server-side-rendering) to learn about this feature. On the other hand, if you are looking for integration with traditional server-side frameworks, check out the [Backend Integration guide](/guides/backend-integration) instead.
</Tip>

## Building the App

You may run `npm run build` command to build the app.

```bash theme={null}
npm run build
```

By default, the build output will be placed at `dist`. You may deploy this `dist` folder to any of your preferred platforms.

### Testing the App Locally

Once you've built the app, you may test it locally by running `npm run preview` command.

```bash theme={null}
npm run preview
```

The `vite preview` command will boot up a local static web server that serves the files from `dist` at `http://localhost:4173`. It's an easy way to check if the production build looks OK in your local environment.

You may configure the port of the server by passing the `--port` flag as an argument.

```json package.json theme={null}
{
  "scripts": {
    "preview": "vite preview --port 8080"
  }
}
```

Now the `preview` command will launch the server at `http://localhost:8080`.

## GitHub Pages

<Steps>
  <Step title="Update Vite Config">
    Set the correct `base` in `vite.config.js`.

    If you are deploying to `https://<USERNAME>.github.io/`, or to a custom domain through GitHub Pages (eg. `www.example.com`), set `base` to `'/'`. Alternatively, you can remove `base` from the configuration, as it defaults to `'/'`.

    If you are deploying to `https://<USERNAME>.github.io/<REPO>/` (eg. your repository is at `https://github.com/<USERNAME>/<REPO>`), then set `base` to `'/<REPO>/'`.
  </Step>

  <Step title="Enable GitHub Pages">
    In your repository, go to **Settings → Pages**. Under **Build and deployment**, open the **Source** dropdown, and select **GitHub Actions**.

    GitHub will now deploy your site using a GitHub Actions [workflow](https://docs.github.com/en/actions/concepts/workflows-and-actions/workflows), which is necessary since Vite requires a build step for deployment.
  </Step>

  <Step title="Create a Workflow">
    Create a new file in your repository at `.github/workflows/deploy.yml`. You can also click on **"create your own"** from the previous step, which will generate a starter workflow file for you.

    Here's a sample workflow that installs dependencies with npm, builds the site, and deploys it whenever you push changes to the `main` branch.
  </Step>
</Steps>

## GitLab Pages and GitLab CI

<Steps>
  <Step title="Set the base in vite.config.js">
    If you are deploying to `https://<USERNAME or GROUP>.gitlab.io/`, you can omit `base` as it defaults to `'/'`.

    If you are deploying to `https://<USERNAME or GROUP>.gitlab.io/<REPO>/`, for example your repository is at `https://gitlab.com/<USERNAME>/<REPO>`, then set `base` to `'/<REPO>/'`.
  </Step>

  <Step title="Create .gitlab-ci.yml">
    Create a file called `.gitlab-ci.yml` in the root of your project with the content below. This will build and deploy your site whenever you make changes to your content:

    ```yaml .gitlab-ci.yml theme={null}
    image: node:lts
    pages:
      stage: deploy
      cache:
        key:
          files:
            - package-lock.json
          prefix: npm
        paths:
          - node_modules/
      script:
        - npm install
        - npm run build
        - cp -a dist/. public/
      artifacts:
        paths:
          - public
      rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    ```
  </Step>
</Steps>

## Netlify

### Netlify CLI

<Steps>
  <Step title="Install Netlify CLI">
    Install the [Netlify CLI](https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli/) via `npm install -g netlify-cli`.
  </Step>

  <Step title="Create a new site">
    Create a new site using `netlify init`.
  </Step>

  <Step title="Deploy">
    Deploy using `netlify deploy`.

    The Netlify CLI will share with you a preview URL to inspect. When you are ready to go into production, use the `prod` flag: `netlify deploy --prod`.
  </Step>
</Steps>

### Netlify with Git

<Steps>
  <Step title="Push to git repository">
    Push your code to a git repository (GitHub, GitLab, BitBucket, Azure DevOps).
  </Step>

  <Step title="Import to Netlify">
    [Import the project](https://app.netlify.com/start) to Netlify.
  </Step>

  <Step title="Configure and deploy">
    Choose the branch, output directory, and set up environment variables if applicable.

    Click on **Deploy**.

    Your Vite app is deployed!
  </Step>
</Steps>

After your project has been imported and deployed, all subsequent pushes to branches other than the production branch along with pull requests will generate [Preview Deployments](https://docs.netlify.com/deploy/deploy-types/deploy-previews/), and all changes made to the Production Branch (commonly "main") will result in a [Production Deployment](https://docs.netlify.com/deploy/deploy-overview/#definitions).

## Vercel

### Vercel CLI

<Steps>
  <Step title="Install Vercel CLI">
    Install the [Vercel CLI](https://vercel.com/cli) via `npm i -g vercel` and run `vercel` to deploy.
  </Step>

  <Step title="Deploy">
    Vercel will detect that you are using Vite and will enable the correct settings for your deployment.

    Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
  </Step>
</Steps>

### Vercel with Git

<Steps>
  <Step title="Push to git repository">
    Push your code to your git repository (GitHub, GitLab, Bitbucket).
  </Step>

  <Step title="Import to Vercel">
    [Import your Vite project](https://vercel.com/new) into Vercel.
  </Step>

  <Step title="Deploy">
    Vercel will detect that you are using Vite and will enable the correct settings for your deployment.

    Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
  </Step>
</Steps>

After your project has been imported and deployed, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/concepts/deployments/environments#preview), and all changes made to the Production Branch (commonly "main") will result in a [Production Deployment](https://vercel.com/docs/concepts/deployments/environments#production).

Learn more about Vercel's [Git Integration](https://vercel.com/docs/concepts/git).

## Cloudflare

### Cloudflare Workers

The [Cloudflare Vite plugin](https://developers.cloudflare.com/workers/vite-plugin/) provides integration with Cloudflare Workers and uses Vite's Environment API to run your server-side code in the Cloudflare Workers runtime during development.

To add Cloudflare Workers to an existing Vite project, install the plugin and add it to your config:

```bash theme={null}
npm install --save-dev @cloudflare/vite-plugin
```

```js vite.config.js theme={null}
import { defineConfig } from 'vite'
import { cloudflare } from '@cloudflare/vite-plugin'

export default defineConfig({
  plugins: [cloudflare()],
})
```

```jsonc wrangler.jsonc theme={null}
{
  "name": "my-vite-app",
}
```

After running `npm run build`, your application can now be deployed with `npx wrangler deploy`.

<Tip>
  You can also easily add backend APIs to your Vite application to securely communicate with Cloudflare resources. This runs in the Workers runtime during development and deploys alongside your frontend. See the [Cloudflare Vite plugin tutorial](https://developers.cloudflare.com/workers/vite-plugin/tutorial/) for a complete walkthrough.
</Tip>

### Cloudflare Pages

#### Cloudflare Pages with Git

Cloudflare Pages gives you a way to deploy directly to Cloudflare without having to manage a Wrangler file.

<Steps>
  <Step title="Push to git repository">
    Push your code to your git repository (GitHub, GitLab).
  </Step>

  <Step title="Access Cloudflare dashboard">
    Log in to the Cloudflare dashboard and select your account in **Account Home** > **Workers & Pages**.
  </Step>

  <Step title="Create new project">
    Select **Create a new Project** and the **Pages** option, then select Git.
  </Step>

  <Step title="Select repository">
    Select the git project you want to deploy and click **Begin setup**.
  </Step>

  <Step title="Configure build settings">
    Select the corresponding framework preset in the build setting depending on the Vite framework you have selected. Otherwise enter your build commands for your project and your expected output directory.

    Then save and deploy!
  </Step>

  <Step title="Your app is deployed">
    Your application is deployed! (e.g `https://<PROJECTNAME>.pages.dev/`)
  </Step>
</Steps>

After your project has been imported and deployed, all subsequent pushes to branches will generate [Preview Deployments](https://developers.cloudflare.com/pages/platform/preview-deployments/) unless specified not to in your [branch build controls](https://developers.cloudflare.com/pages/platform/branch-build-controls/). All changes to the Production Branch (commonly "main") will result in a Production Deployment.

You can also add custom domains and handle custom build settings on Pages. Learn more about [Cloudflare Pages Git Integration](https://developers.cloudflare.com/pages/get-started/#manage-your-site).

## Google Firebase

<Steps>
  <Step title="Install firebase-tools">
    Install [firebase-tools](https://www.npmjs.com/package/firebase-tools) via `npm i -g firebase-tools`.
  </Step>

  <Step title="Create configuration files">
    Create the following files at the root of your project:

    <CodeGroup>
      ```json firebase.json theme={null}
      {
        "hosting": {
          "public": "dist",
          "ignore": [],
          "rewrites": [
            {
              "source": "**",
              "destination": "/index.html"
            }
          ]
        }
      }
      ```

      ```js .firebaserc theme={null}
      {
        "projects": {
          "default": "<YOUR_FIREBASE_ID>"
        }
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Deploy">
    After running `npm run build`, deploy using the command `firebase deploy`.
  </Step>
</Steps>

## Other Platforms

<Accordion title="Surge">
  <Steps>
    <Step title="Install Surge">
      Install [surge](https://www.npmjs.com/package/surge) via `npm i -g surge`.
    </Step>

    <Step title="Build and deploy">
      Run `npm run build`.

      Deploy to surge by typing `surge dist`.
    </Step>
  </Steps>

  You can also deploy to a [custom domain](https://surge.sh/help/adding-a-custom-domain) by adding `surge dist yourdomain.com`.
</Accordion>

<Accordion title="Azure Static Web Apps">
  You can quickly deploy your Vite app with Microsoft Azure [Static Web Apps](https://aka.ms/staticwebapps) service. You need:

  * An Azure account and a subscription key. You can create a [free Azure account here](https://azure.microsoft.com/free).
  * Your app code pushed to [GitHub](https://github.com).
  * The [SWA Extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestaticwebapps) in [Visual Studio Code](https://code.visualstudio.com).

  Install the extension in VS Code and navigate to your app root. Open the Static Web Apps extension, sign in to Azure, and click the '+' sign to create a new Static Web App. You will be prompted to designate which subscription key to use.

  Follow the wizard started by the extension to give your app a name, choose a framework preset, and designate the app root (usually `/`) and built file location `/dist`. The wizard will run and will create a GitHub action in your repo in a `.github` folder.

  The action will work to deploy your app (watch its progress in your repo's Actions tab) and, when successfully completed, you can view your app in the address provided in the extension's progress window by clicking the 'Browse Website' button that appears when the GitHub action has run.
</Accordion>

<Accordion title="Render">
  You can deploy your Vite app as a Static Site on [Render](https://render.com/).

  <Steps>
    <Step title="Create a Render account">
      Create a [Render account](https://dashboard.render.com/register).
    </Step>

    <Step title="Create new Static Site">
      In the [Dashboard](https://dashboard.render.com/), click the **New** button and select **Static Site**.
    </Step>

    <Step title="Connect repository">
      Connect your GitHub/GitLab account or use a public repository.
    </Step>

    <Step title="Configure project">
      Specify a project name and branch.

      * **Build Command**: `npm install && npm run build`
      * **Publish Directory**: `dist`
    </Step>

    <Step title="Deploy">
      Click **Create Static Site**. Your app should be deployed at `https://<PROJECTNAME>.onrender.com/`.
    </Step>
  </Steps>

  By default, any new commit pushed to the specified branch will automatically trigger a new deployment. [Auto-Deploy](https://render.com/docs/deploys#toggling-auto-deploy-for-a-service) can be configured in the project settings.

  You can also add a [custom domain](https://render.com/docs/custom-domains) to your project.
</Accordion>

<Accordion title="Flightcontrol">
  Deploy your static site using [Flightcontrol](https://www.flightcontrol.dev/?ref=docs-vite) by following these [instructions](https://www.flightcontrol.dev/docs/reference/examples/vite?ref=docs-vite).
</Accordion>

<Accordion title="Kinsta Static Site Hosting">
  Deploy your static site using [Kinsta](https://kinsta.com/static-site-hosting/) by following these [instructions](https://kinsta.com/docs/static-site-hosting/static-site-quick-start/react-static-site-examples/#react-with-vite).
</Accordion>

<Accordion title="xmit Static Site Hosting">
  Deploy your static site using [xmit](https://xmit.co) by following this [guide](https://xmit.dev/posts/vite-quickstart/).
</Accordion>

<Accordion title="Zephyr Cloud">
  [Zephyr Cloud](https://zephyr-cloud.io) is a deployment platform that integrates directly into your build process and provides global edge distribution for module federation and other kind of applications.

  Zephyr follows a different approach than other cloud providers. It integrates directly with Vite build process, so every time you build or run the dev server for your application, it will be automatically deployed with Zephyr Cloud.

  Follow the steps in [the Vite deployment guide](https://docs.zephyr-cloud.io/bundlers/vite) to get started.
</Accordion>

<Accordion title="EdgeOne Pages">
  Deploy your static site using [EdgeOne Pages](https://edgeone.ai/products/pages) by following these [instructions](https://pages.edgeone.ai/document/vite).
</Accordion>
