Skip to content

Deploying a Static Site

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, 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.
  • Wite is installed as a local dev dependency in your project, and you have setup the following npm scripts:
{
  "scripts": {
    "build": "wite build",
    "preview": "wite preview"
  }
}

It is important to note that wite preview is intended for previewing the build locally and not meant as a production server.

NOTE

These guides provide instructions for performing a static deployment of your Wite site. Wite 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 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 instead.

Building the App

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

$ 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.

$ npm run build
$ npm run preview

The wite preview command will boot up 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 --port flag as an argument.

{
  "scripts": {
    "preview": "wite preview --port 8080"
  }
}

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

GitHub Pages

  1. Set the correct base in wite.config.js.

    If you are deploying to https://<USERNAME>.github.io/, you can omit base as it defaults to '/'.

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

  2. Inside your project, create deploy.sh with the following content (with highlighted lines uncommented appropriately), and run it to deploy:













     






     


     




    #!/usr/bin/env sh
    
    # abort on errors
    set -e
    
    # build
    npm run build
    
    # navigate into the build output directory
    cd dist
    
    # if you are deploying to a custom domain
    # echo 'www.example.com' > CNAME
    
    git init
    git checkout -b main
    git add -A
    git commit -m 'deploy'
    
    # if you are deploying to https://<USERNAME>.github.io
    # git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git main
    
    # if you are deploying to https://<USERNAME>.github.io/<REPO>
    # git push -f git@github.com:<USERNAME>/<REPO>.git main:gh-pages
    
    cd -
    

TIP

You can also run the above script in your CI setup to enable automatic deployment on each push.

GitLab Pages and GitLab CI

  1. Set the correct base in wite.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>/'.

  2. 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:

    image: node:16.5.0
    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
    

Netlify

  1. Install the Netlify CLI.
  2. Create a new site using ntl init.
  3. Deploy using ntl deploy.
# Install the Netlify CLI
$ npm install -g netlify-cli

# Create a new site in Netlify
$ ntl init

# Deploy to a unique preview URL
$ ntl 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:

# Deploy the site into production
$ ntl deploy --prod

Vercel

Vercel CLI

  1. Install the Vercel CLI and run vercel to deploy.
  2. Vercel will detect that you are using Wite and will enable the correct settings for your deployment.
  3. Your application is deployed!
$ npm i -g vercel
$ vercel init wite
Vercel CLI
> Success! Initialized "wite" example in ~/your-folder.
- To deploy, `cd wite` and run `vercel`.

Vercel for Git

  1. Push your code to your git repository (GitHub, GitLab, Bitbucket).
  2. Import your Wite project into Vercel.
  3. Vercel will detect that you are using Wite and will enable the correct settings for your deployment.
  4. Your application is deployed!

After your project has been imported and deployed, all subsequent pushes to branches will generate Preview Deployments, and all changes made to the Production Branch (commonly “main”) will result in a Production Deployment.

Learn more about Vercel’s Git Integration.

Cloudflare Pages

Cloudflare Pages via Wrangler

  1. Install Wrangler CLI.
  2. Authenticate Wrangler with your Cloudflare account using wrangler login.
  3. Run your build command.
  4. Deploy using npx wrangler pages publish dist.
# Install Wrangler CLI
$ npm install -g wrangler

# Login to Cloudflare account from CLI
$ wrangler login

# Run your build command
$ npm run build

# Create new deployment
$ npx wrangler pages publish dist

After your assets are uploaded, Wrangler will give you a preview URL to inspect your site. When you log into the Cloudflare Pages dashboard, you will see your new project.

Cloudflare Pages with Git

  1. Push your code to your git repository (GitHub, GitLab).
  2. Log in to the Cloudflare dashboard and select your account in Account Home > Pages.
  3. Select Create a new Project and the Connect Git option.
  4. Select the git project you want to deploy and click Begin setup
  5. Select the corresponding framework preset in the build setting depending on the Wite framework you have selected.
  6. Then save and deploy!
  7. Your application is deployed! (e.g https://<PROJECTNAME>.pages.dev/)

After your project has been imported and deployed, all subsequent pushes to branches will generate Preview Deployments unless specified not to in your 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.

Google Firebase

  1. Make sure you have firebase-tools installed.

  2. Create firebase.json and .firebaserc at the root of your project with the following content:

    firebase.json:

    {
      "hosting": {
        "public": "dist",
        "ignore": [],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      }
    }
    

    .firebaserc:

    {
      "projects": {
        "default": "<YOUR_FIREBASE_ID>"
      }
    }
    
  3. After running npm run build, deploy using the command firebase deploy.

Surge

  1. First install surge, if you haven’t already.

  2. Run npm run build.

  3. Deploy to surge by typing surge dist.

You can also deploy to a custom domain by adding surge dist yourdomain.com.

Heroku

  1. Install Heroku CLI.

  2. Create a Heroku account by signing up.

  3. Run heroku login and fill in your Heroku credentials:

    $ heroku login
    
  4. Create a file called static.json in the root of your project with the below content:

    static.json:

    {
      "root": "./dist"
    }
    

    This is the configuration of your site; read more at heroku-buildpack-static.

  5. Set up your Heroku git remote:

    # version change
    $ git init
    $ git add .
    $ git commit -m "My site ready for deployment."
    
    # creates a new app with a specified name
    $ heroku apps:create example
    
  6. Set buildpacks. We use heroku/nodejs to build the project and heroku-buildpack-static to serve it.

    # set buildpacks
    $ heroku buildpacks:set heroku/nodejs
    $ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static.git
    
  7. Deploy your site:

    # publish site
    $ git push heroku main
    
    # opens a browser to view the Dashboard version of Heroku CI
    $ heroku open
    

Azure Static Web Apps

You can quickly deploy your Wite app with Microsoft Azure Static Web Apps service. You need:

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.

Released under the MIT License.