Vue自動打包發布Git


我們平時打包和發布的流程

 

1.修改package.json

"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "build": "node build/build.js",
    "deploy": "node build/deployer.js"
  },

添加key為deploy,我們可以通過 npm run deploy來執行 node build/deployer.js

2.新建文件deployer.js

 2.1檢測dist文件是否存在

fs.exists(deployDir)

2.2 存在刪除

spawn('rm',['-rf',deployDir])

2.3 打包

spawn('node', ['build/build.js'])

2.4添加gitHub

github:{
      url:'https://github.com/shuo1209/Vue_deploy.git',
      branch:'master',
    },

2.5 進行上傳

gitPush = () =>{
    return git('add', '-A').then( (msg) => {
    return git('commit', '-m', message).catch( () =>{
     });
    }).then( () => {
    return git('push', '-u', repo.url, 'master:' + repo.branch, '--force');
    });
} 

3.鏈式調用

// 1.檢測文件夾dist是否存在
// 2.build
// 3.發布
fs.exists(deployDir).then( (exist) => {
    log.info('-----------------------start--------------------');
    if (exist) return clear();
    return build();
}).then(() => {
    return config.github;
}).then((repo) =>{
    return gitPush(repo);
}).then(() =>{
    log.info('-----------------------finish-------------------');
})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM