Deploying build folder to heroku

While Deploying your node project to heroku, and if your project is using a separate build/dist folder, adding everything in the main folder to the heroku repo may not be the idle solution. You may only want to push the compiled files (which is generated by webpack or gulp) in a subfolder.

One solution is to add the heroku repo inside dist folder. So you can add all the files inside that and push to heroku repo. But you have to keep a gitignore file. Add task i your build tool to not to remove .git inside dist folder etc.

Another solution is to add the different commands into a js file and execute them. following is one such example

import { spawnSync } from 'child_process'
import {remote, version} from './package.json'

function deploy() {
options = {
    cwd: path.resolve(__dirname, './dist')
  };
  //push dist folder to deploy repo
  spawnSync('git',['init'],options);
  console.log('Initialising Repository');
  spawnSync('git',['init'],options);
  console.log('Adding remote url');
  spawnSync('git',['remote','add', remote.name, remote.gitPath],options)
  console.log('Add all files');
  spawnSync('git',['add','.','--all'],options)
  console.log(`Commit with v${version}`);
  spawnSync('git', ['commit','-m',`v${version}`], options)
  console.log('Push the changes to repo');
  spawnSync('git', ['push', '-f', remote.name, 'master'],options)
}

Keep couple of config values in separate file. eg. package.json and read that in this. A bump version plugin will help you increase release version as well about that in next post.