How can I combine two gulp tasks

I am using gulp

to compile typescript files and create a file output.js

.

Is it possible to have one task that compiles the typescript file and merges it with the angular libraries?

This is what my current file looks like (below). It first runs a typescript task that creates the file output.js

, and then runs a scripting task that concatenates the plugin script and output.js

.

'use strict';
var gulp = require('gulp')

var paths = {
  distScriptsDir: '../../Themes/mastter/Scripts',
  srcScriptsPlugins: [
    'node_modules/jquery/dist/jquery.min.js',
    'node_modules/angular/angular.min.js',
    'node_modules/angular-route/angular-route.min.js',
    'node_modules/angular-translate/dist/angular-translate.min.js',
    'node_modules/angular-translate/dist/angular-translate-loader-url/angular-translate-loader-url.min.js',
    'node_modules/angular-bootstrap/dist/ui-bootstrap-tpls.js',
    'Scripts/angular-sticky.min.js',
    'Scripts/dragme.js',
    'Scripts/jasny-bootstrap.min.js',
    'node_modules/lodash/dist/lodash.min.js',
    'node_modules/angular-google-maps/dist/angular-google-maps.min.js'
  ],
  srcScriptsFile: [
    'output.js'
  ]
};


//typescript
gulp.task('typescript', function () {
  var ts = require('gulp-typescript');
  var tsResult = gulp.src( 'all.ts')
    .pipe(ts({
      noImplicitAny: true,
      out: 'output.js'
    }));
  return tsResult.js.pipe(gulp.dest(''));
});

// scripts task
gulp.task('scripts', function () {

  var concat = require('gulp-concat'),
      plumber = require('gulp-plumber'),
      uglify = require('gulp-uglify');

  return gulp.src(paths.srcScriptsPlugins.concat(paths.srcScriptsFile))
    .pipe(plumber({
      errorHandler: function (e) {
          console.log(e.toString());
          this.emit('end');
      }
    }))
  //    .pipe(uglify())
  .pipe(concat('main.js'))
  .pipe(gulp.dest(paths.distScriptsDir));

});

// default task
gulp.task('default', [
 'typescript',
  'scripts'
 ]);

      

+3


source to share


2 answers


I use a watch for this which has a heap gulp.watch

inside it. One to view the .ts changes and runs the typescript compiler that will output the js file anywhere and the other gulp.watch

that monitors the .js files and runs the script task. In this case, everything will be automated with a clock, and you do not need to combine the task into one task.



gulp.task('watch', function() {
    gulp.watch(['dir/*.ts','otherdir/*.ts',...], ['typescript']);
    gulp.watch(['dir/*.js','otherdir/*.js',...], ['scripts']); //make sure to include the .ts result folder...
});

      

0


source


try run-sequence . Below is a simple example.



gulp.task('task1', function(callback) {
  setTimeout(function() {
    console.log('task1 is done');
    callback()
  }, 1000);
});

gulp.task('task2', function(callback) {
  setTimeout(function() {
    console.log('task2 is done');
    callback()
  }, 2000);
});

gulp.task('tk12', function(callback) {
  return runSequence('task1', 'task2', callback);
});
      

Run code


0


source







All Articles