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