vue cli3 Project Automated Deployment to Server after Packaging
- 2021-08-21 19:42:59
- OfStack
1. Install scp2
npm install scp2 --save-dev
STEP 2 Write a script
For example, upload. js (just choose one of the following)
The position is equal to package. json.
Abbreviated version
'use strict'
// Introduce scp2
var client = require('scp2');
client.scp('./dist/', { // Location of locally packaged files
"host": 'XXX.XX.XX.XXX', // Server's IP Address
"port": 'XX', // Server port, 1 Be general 22
"username": 'XXX', // User name
"password": '*****', // Password
"path": 'XXX' // Server destination location for project deployment
}, err =>{
if (!err) {
console.log(" Project release completed !")
} else {
console.log("err", err)
}
})
Slightly beautify the output of the console
'use strict'
// Introduce scp2
var client = require('scp2');
// Below 3 Plug-ins are used for console beautification at deployment time Optional or not
const ora = require('ora');
const chalk = require('chalk');
const spinner = ora(chalk.green(' Publishing to server ...'));
spinner.start();
client.scp('./dist/', { // Location of locally packaged files
"host": 'XXX.XX.XX.XXX', // Server's IP Address
"port": 'XX', // Server port, 1 Be general 22
"username": 'XXX', // User name
"password": '*****', // Password
"path": 'XXX' // Server destination location for project deployment
}, err =>{
spinner.stop();
if (!err) {
console.log(chalk.green(" Project release completed !"))
} else {
console.log("err", err)
}
})
✨ remembers ignoring this file when uploading the project git, because it contains your server address, user and password
3. Add the scripts command in package. json
"upload": "node upload.js",
"deploy": "npm run build && npm run upload"
Step 4 Execute the script
npm run deploy
After running this script command, it will first
npm run build
Execute the package command, and then execute the
node upload.js
Upload the packaged file to the server