栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

工程化一键部署

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

工程化一键部署

前端项目资源一键部署服务 首先
首先安装   shelljs和ssh2-sftp-client
 npm i shelljs ssh2-sftp-client --save-dev
然后
修改package.json增加上传命令
    "uploadServes": "node uploadServes/index.js"
新建 打包上传操作
index.js


const config = require('./config.js');
const shell = require('shelljs');
const path = require('path');
let Client = require('ssh2-sftp-client');
// 打包 npm run build
const compileDist = async () => {
  if (shell.exec(`npm run build`).code == 0) {
    console.log('打包成功');
  }
};

async function connectSSh() {
  let sftp = new Client();
  sftp
    .connect({
      host: config.ip, // 服务器 IP
      port: config.port,  //  服务器端口
      username: config.username,  // 登陆用户名
      password: config.password, // 登陆用户密码
    })
    .then(() => {
      console.log('先执行删除服务器文件');
      //. config.rmpath。需要删除服务器文件的地址
      return sftp.rmdir(config.rmpath, true);
    })
    .then(() => {
      // 上传文件
      console.log('开始上传');
      //。config.path  上传文件到服务器的地址
      return sftp.uploadDir(path.resolve(__dirname, '../dist'), config.path);
    })
    .then(data => {
      console.log('上传完成');
      sftp.end();
    })
    .catch(err => {
      console.log(err, '失败');
      sftp.end();
    });
}
async function runTask() {
  await compileDist(); //打包完成
  await connectSSh(); //提交上传
}
runTask();

运行. npm run

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/604377.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号