当前位置: 首页 > 工具软件 > ShellJS > 使用案例 >

npm install shelljs --save-dev 一句命令执行vue构建 git三连

赵禄
2023-12-01

第一步先npm install shelljs --save-dev 先安装
第二步package.json中配置自定义命令

"scripts": {
    "dev": "vue-cli-service serve",
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "deploy": "push-dir --dir=dist --remote=deploy --branch=master",
    "push" : "node ./push.js" //新加
  },

第三步创建push.js文件 和package.json同级
push.js文件

//局部模式
var shell = require('shelljs');
//全局模式下,就不需要用shell开头了。
//require('shelljs/global');

if (shell.exec('npm run build').code !== 0) {//执行npm run build 命令
  shell.echo('Error: Git commit failed');
  shell.exit(1);
}

//由于我的用另外一个仓库存放dist目录,所以这里要将文件增量复制到目标目录。并切换到对应目录。
shell.cp ('-r', './dist/*', '../qindao_frontend_ui_dist');
shell.cd('../qindao_frontend_ui_dist');
shell.exec('git pull origin master');
shell.exec('git add .');
shell.exec("git commit -m 'autocommit'")
shell.exec('git push origin master')
 类似资料: