Search code examples
vue.jsnginxnpmvuexnuxt.js

How to deploy a finished nuxt.js app to a webserver?


At work, I got some little insight to nuxtjs development and I got very interested in it. So, I started developing on my own a little bit, but now, I'm stuck with my finished project.

To develop, I spin up a local server with "npm run dev" in my CLI. This all works fine.

But, how do I deploy my now finished project to run it in something like nginx (or are there better alternatives that run on an Windows Server environment) on my home server? I heard about "npm run build" into my CLI, but how is the procedure beyond that? And is that command even the right method?

I'm absolutely a noob in this department. Could anybody teach me step by step what I have to do to go "in production"?

Thank's very much in advance!

Max

Of course, "npm run dev" isn't a viable option for production. It's only accessable from the machine the server is running on.


Solution

  • The simplest way - you need to generate all the content:

    1. Run npm run generate.
    2. Go to the dist subfolder of your project and copy all from there to some public hosting, like GitHub Pages.

    Though if you have some content depended from the user, you need to deploy it as a SPA:

    1. Change mode in nuxt.config.js to spa.
    2. Run npm run build.
    3. Deploy the created dist/ folder to your static hostings like Surge, GitHub Pages or nginx.

    More details:

    https://nuxtjs.org/guide/commands#static-generated-deployment-pre-rendered-

    https://nuxtjs.org/faq/github-pages#how-to-deploy-on-github-pages-