4

I'm trying to annotate and minify a systemjs angular project. Systemjs comes with a build function, but it is not `'gulp-aware'. There is the possibility to pass the builder an option to minify, but there is not one for ng-annotate, so I will need gulp to do both for me instead.

gulp.task('bundle', function () {
    var options = {}
    builder.buildStatic('./assets/app/app.js', options)
    .then(function(data) {
        console.log("then called");
        // make data available for another task            
    });

How can I combine the above with

gulp.task('productionApp', function() {
    return [source the output from 'bundle']
    .pipe(ngannotate())
    .pipe(uglify())
    .pipe(gulp.dest('./dist'));
});

I could just output the first task to a file, and then .src that in, but that can't be the best way?

Simon H
  • 17,952
  • 10
  • 57
  • 101

2 Answers2

1

The simplest way is to save it inside a buffer (actually, a simple object), then make a stream of and continue as you would with src.

Gulp's repository contains a recipe how it's done.

Note: you should make all those load-* tasks to run at the very beginning, you can either use run-sequence as they've done or make them as dependencies of the "real" tasks.

Roy Miloh
  • 3,216
  • 1
  • 15
  • 16
  • Yikes - this is really complicated. Makes me think I am looking at the problem the wrong way somehow? – Simon H Sep 27 '15 at 15:48
  • Why complicated? pretty straight forward and elegant. You can always save it inside an intermediate directory as you suggested, but it could be slower. In addition, you can build an abstraction on-top of it to get things easier. Anyway, this way you can "communicate" (data) between tasks without save the actual data in fs. – Roy Miloh Sep 27 '15 at 16:01
  • OK, I may try again, but now I see that ng-annotate + systemjs is also a bit fiddly. Life on the bleeding edge... – Simon H Sep 27 '15 at 16:03
0

The yargs package on npm exports the object argv, wich is a very clever representation of the command-line params. For example, the invocation

gulp -a test -b 123 my-task

is represented during the run by a param argv with value

{ a: 'test', b: 123 }

which is passed to the gulp task my-task and, before it, to all its predecessors.

If one of the predecessors assigns a new prop to argv

argv.newProp = 'newValue'

this prop will be available to all its successors, including the task that you really want to execute.

The instruction const { argv } = require('yargs') is to be put at the start of the gulpfile, and it can be enriched with aliases and defaults. Reference is here

Marco Faustinelli
  • 2,760
  • 4
  • 24
  • 34