初始化vue项目, 测试服务已经准备(前提已经准备好了)
注意: 一键部署 vue2.0~3.0 都可以使用
1、在根目录 新建deploy 文件夹:
.env.dev类容如下
VUE_APP_SERVER_ID=0
.env.prod类容如下
VUE_APP_SERVER_ID=1
index.js 文件类容如下:
const scpClient = require('scp2');
const ora = require('ora');
const chalk = require('chalk');
const server = require('./products');
const spinner = ora('正在发布到' + server.name + '服务器...\n');
const spinnerCopy = ora('正在备份到' + server.name + '服务器...\n');
const ssh2 = new (require('ssh2').Client)(); // 版本新增
const compressing = require('compressing');
// 生成zip压缩包的名字(根据自己的需要自定义)
const filePath = "./" + (new Date()).getTime() + server.assetsRoot.replace('./', '') + ".zip";
ssh2.on('ready', () => {
console.log(chalk.green('连接服务成功...'));
ssh2.exec("rm -rf " + server.path + '/static', (err,stream)=> {
console.log(chalk.green('正在删除缓存历史文件...\n'));
if (err) {console.log(chalk.red('删除失败.\n')); throw err;}
stream.on("close", ()=>{
ssh2.end();
uploadFile();
backups();
});
});
}).connect({
host: server.host,
port: server.port,
username: server.username,
password: server.password,
path: server.path
<