porting PRs #18392 and #18441 to 4.x
This is a precursor to bringing in some of the gulp tasks from angular.io, which could lead to the gulpfile becoming unwieldy.