This guide shows you how to deploy a Vue.js application on Layer0.

Layer0 only supports Node.js version 14.x

If you do not have Node.js installed on your system, download and install it from the official Node.js v14.x downloads page. Select the download that matches your operating system and run the installer. Note that the installer for Node.js will also install npm.

Note that while you can use any version of Node.js >= 14 locally, your app will run in Node 14 when deployed to the Layer0 cloud. Therefore we highly suggest using Node 14 for all development.

Deploying requires an account on Layer0. Sign up here for free..

If you have not already done so, install the Layer0 CLI

npm i -g @layer0/cli

If you don't already have a Vue.js app, create one by using the Vue CLI:

npm install -g @vue/cli @vue/cli-service-global
vue create hello-world

When running vue create select Vue 2 as a preset,

Vue CLI v4.5.7
? Please pick a preset: (Use arrow keys)
❯ Default ([Vue 2] babel, eslint)
  Default (Vue 3 Preview) ([Vue 3] babel, eslint)
  Manually select features

You can verify your app works by running it locally:

cd hello-world
npm run serve

You should see an output like this in the terminal:

 DONE  Compiled successfully in 1667ms                                9:54:44 AM


  App running at:
  - Local:   http://localhost:8080/
  - Network: http://172.20.10.8:8080/

  Note that the development build is not optimized.
  To create a production build, run npm run build.

In the root directory of your project run layer0 init:

layer0 init

This will automatically update your package.json and add all of the required Layer0 dependencies and files to your project. These include:

  • The @layer0/core package - Allows you to declare routes and deploy your application on Layer0
  • The @layer0/prefetch package - Allows you to configure a service worker to prefetch and cache pages to improve browsing speed
  • layer0.config.js - A configuration file for Layer0
  • routes.js - A default routes file that sends all requests to Vue.js.

Next you'll need to configure Layer0 routing in the routes.js file.

For the Vue hello-world template, replace the routes.js file that was created during layer0 init with the following:

const { Router } = require('@layer0/core/router')

module.exports = new Router()
  // Send requests to static assets in the build output folder `dist`
  .static('dist')

  // Send everything else to the App Shell
  .fallback(({ appShell }) => {
    appShell('dist/index.html')
  })

The example above assumes you're using Vue as a single page app. It routes the static assets (JavaScript, CSS, and Images) in the production build folder dist and maps all other requests to the app shell in dist/index.html.

Refer to the Routing guide for the full syntax of the routes.js file and how to configure it for your use case.

Create a production build of your app by running the following in your project's root directory:

npm run build

Run Layer0 on your local machine:

npm run layer0:dev

Load the site: http://127.0.0.1:3000 !

Create a production build of your app by running the following in your project's root directory:

npm run build

Next, deploy the build to Layer0 by running the layer0 deploy command:

layer0 deploy

Refer to the Deploying guide for more information on the deploy command and its options.

For server side rendered Vue.js apps we recommend using the Nuxt.js framework which is supported on Layer0. Refer to the Nuxt guide for more information.