nuxt command and deployment

Nuxt.js offers a range of commonly used commands for the development or deployment of publishing.

 

 You can add these commands to  package.json:

"scripts": {
  "dev": "nuxt",
  "build": "nuxt build",
  "start": "nuxt start",
  "generate": "nuxt generate"
}

The actual project with nuxt generated commands are:

"scripts": {
    "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
    "build": "nuxt build",
    "start": "cross-env NODE_ENV=production node server/index.js",
    "generate": "nuxt generate"
  },

Development model

Services can start Nuxt loaded with hot features in development mode with the following command:

nuxt
 // or 
npm run dev

Published deployment

Nuxt.js release offers two ways to deploy applications: server-side rendering static application deployment and application deployment.

Server-side rendering application deployment

Application deployment Nuxt.js server rendering can not directly use the  nuxt command, but should be compiled to build, and then start Nuxt service, can be accomplished by the following two commands:

nuxt build
nuxt start

Recommended  package.json configuration is as follows:

{
  "name": "my-app",
  "dependencies": {
    "nuxt": "latest"
  },
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start"
  }
}

Static application deployment

Nuxt.js can be based on static routing configuration will be applied, so that we can deploy applications to any static site hosting service provider.

Use the following command to generate static directories and files applications:

npm run generate

This command creates a  dist folder, all resource files which were static.

Single Page Application Deployment (SPA)

nuxt generate In the build / generate SSR engine still needs time, but also has the advantage of pre-rendered all of the pages, and has a high SEO optimization and page load capacity. Content generation when building. For example, we can not use it for user authentication depends on the content or the application of real-time API (at least for the first load).

The idea SPA application is very simple! SPA mode is enabled when using  mode: 'spa' or  --spa, and we run the Package, generated automatically activated after the Herald, it generates a common meta and links to resources, but does not include the content of the page.

Thus, for SPA deployment, you must do the following:

 

 Another possible method of deployment is in spathe frame mode Nuxt as middleware. This helps to reduce server load and use Nuxt the project can not be in the SSR.

 

 

Guess you like

Origin www.cnblogs.com/fqh123/p/12593754.html