Nuxt.Js Deploy without node_modules folder on Azure

Viewed 557

I have nuxt.js APP with SSR that is being deployed on Azure. All good and it works except that the deployment process takes like 10 minutes due to the node_modules folder.

On the server side, there is a 'standard' node js server setup. The artifact structure that is being deployed looks like in the screenshot.

enter image description here

The deployment takes about 10 minutes and that is due to the node_modules folder. If I remove node_modules from the artifact the app stops working.

I looked around but couldn't find any good reference, of how to deploy nuxt.js app with SSR and without the node_modules folder on the server.

As I understand from the link below the .nuxt folder should be enough on the server, but I don't know how to get it running. Maybe it has something with the server setup?

https://nuxtjs.org/docs/2.x/get-started/commands/#production-deployment

Any tips are welcomed.

2 Answers

from your question I would assume, that you want to deploy a SSR (not static) application to azure. If this is the case, it is true that you only need the .nuxt folder.

To help you with the question of the deployment I need more information. What is your setup, how do you deploy it? Why isn't simply transferring only the .nuxt folder working?

You have to edit the nuxt.config.js file so that the target is server.

Ex:

module.exports = {
    target: 'server',
    // Global page headers: https://go.nuxtjs.dev/config-head
    head: {
        title: 'Test',
        htmlAttrs: {
            lang: 'dk'
        },
        meta: [
            { charset: 'utf-8' },
            { name: 'viewport', content: 'width=device-width, initial-scale=1' },
            { hid: 'description', name: 'description', content: '' }
        ],
        link: [
            { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
        ]
    },

...
}

After a build you can package the artifacts without node_modules and it should work. You can try to do this locally:

  1. npm i
  2. npm run build
  3. rm -rf node_modules
  4. npm start

This should be able to run with no issues.

Related