0

I'm running my build with ng build --watch, and I'd like to run a batch file after each build. How do I go about this?

harriyott
  • 10,505
  • 10
  • 64
  • 103
  • 1
    If you want to run two processes in parallel from a package script, I've found `concurrently` useful. But if you're asking if Angular CLI exposes such a hook; see https://github.com/angular/angular-cli/wiki/build (it doesn't). – jonrsharpe Mar 29 '18 at 12:42
  • 1
    I've also looked for this functionality in Angular CLI many times, and nope, doesn't exist ): – Joe Clay Mar 29 '18 at 12:44

1 Answers1

1

You need to use a build tool.

I recommend GulpJS

In your gulpfile something like this:

const spawn = require('child_process').spawn;

... 
gulp.task('your-batch-function-here'], function (cb) {
  <<your custom task here>>
});

gulp.task('ng-build', [], function (cb) {
  spawn('npm', ['run', 'build'], {stdio: 'inherit'})
});

gulp.task('build', ['ng-build', 'your-batch-function-here'], function () {
});

If you start this with gulp build, it will 1. run ann npm run build command 2. After it is finished, will run your batch function task (you must implement it as a gulp.task)

ForestG
  • 17,538
  • 14
  • 52
  • 86