Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add gulp task to angular cli build

I'm switching my deployment tool for an Angular 4 project to angular/cli. The command ng build will put the resulting bundles in a dist folder by default.

I need to figure out how to add my custom task to this process. Specifically, I have a lot of .svg files that I need to bundle and minify into a sprite.defs.svg file, and place the result in dist/assets/svg/. With my previous deployment toolchain, I used gulp with the gulp-svg-sprite plugin. Here was my bundling step:

const svgSprite = require('gulp-svg-sprite');

gulp.src('**/*.svg')
  .pipe(svgSprite({
    mode: {
      defs: {
        dest:'.',
        sprite:"sprite.defs.svg"
      }
    }
  }))
  .pipe(gulp.dest('dist/assets/svg'));

Is there a simple way to integrate something like this into angular/cli's ng build?

like image 513
BeetleJuice Avatar asked Sep 25 '26 20:09

BeetleJuice


1 Answers

Say, you manually run this gulp task as

gulp processSVG

In the scripts section of package.json, define a command like this:

"prebuild": "gulp processSVG"

npm script is smart enough to run the command with the "pre" prefix before the command with the same name, but without this prefix. Now, run the following command:

npm run build

This command will run the prebuild command first and then the build command.

like image 168
Yakov Fain Avatar answered Sep 27 '26 08:09

Yakov Fain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!