preface
Document the steps of the nuxT build project, package it, and deploy it to the server
See the first article for server connection preparation
Nuxt.js server rendering application deployment
Nuxt.js server rendering applications should not use the Nuxt command directly, but should first compile and build, and then start the Nuxt service.
nuxt build
nuxt start
Copy the code
The official recommended package.json configuration is as follows
{
"name": "my-app"."dependencies": {
"nuxt": "latest"
},
"scripts": {
"dev": "nuxt"."build": "nuxt build"."start": "nuxt start"}}Copy the code
Nuxt: start a hot loaded Web server (development mode) nuxt build: build an application using WebPack, compress JS and CSS resources (for distribution). Nuxt start: Start a Web server in build mode (nuxt build is executed first).
Nuxt.js package deployment
Step 1: Pack
Nuxt is automatically packaged when NPM run build is executed.
Step 2, select the file to deploy:
Several required files and folders need to be uploaded to the server
Json file configuration file nuxt.config.js file (if you are configuring proxy, port number, etc.)Copy the code
Step 3, install dependencies
You can upload the required directory to the server /root/my-nuxt (my-nuxt)
Step 4: Modify the configuration file
To modify the server configuration, run the nuxt.config.js command
Open the console and enter
vim nuxt.config.js
Copy the code
The inputa
ori
Enter the edit mode, change the IP address or port number, and pressEsc
And enter the:wq
Save and exit:q
Directly out of
Step 5: Start your NUXT:
Use Pm2 to launch your nuxt.js
$NPM install // or YARN install If dependency is not installed or dependency is changed $pm2 start NPM --name "my-nuxt" -- run startCopy the code
After the startup is complete, run the pm2 commandpm2 list
Check the node service that has been started
To stop the service, run the pm2 stop my-nuxt command, run the pm2 restart my-nuxt command to restart the service, and run the pm2 delete my-nuxt command to delete the service
.
If the online environment needs to use the Nginx service to configure load balancing or map port 80 to port 3000 of the NUXT service, you need to configure the Nginx server