
var gulp = require('gulp'),
  connect = require('gulp-connect'),
  opn = require('opn'),
  autopolyfiller = require('gulp-autopolyfiller'),
  concat = require('gulp-concat'),
  wrap = require("gulp-wrap"),
  isDist = process.argv.indexOf('serve') === -1;


gulp.task('connect', function() {
  connect.server({
    root: './',
    livereload: true
  });
});

gulp.task('recheck', function() {
  return gulp.src('*')
    .pipe(connect.reload());
});

gulp.task('open', ['connect'], function (done) {
  opn('http://localhost:8080', done);
});

gulp.task('autopolyfiller', function () {
    return gulp.src('./src/heartbeat.js')
        .pipe(autopolyfiller('polyfills.js'))
        .pipe(gulp.dest('./src'));
});

gulp.task('scripts', function() {
  return gulp.src(['./src/*.js'])
    .pipe(wrap('; (function(window) {<%= contents %>})(window);'))
    .pipe(concat('heartbeat.js'))
    .pipe(gulp.dest('./dist/'));
});


gulp.task('watch', function() {
  gulp.watch('./src/*.js', ['scripts', 'autopolyfiller', 'recheck']);
});

gulp.task('serve', ['scripts', 'open', 'watch']);

gulp.task('build', ['scripts']);

@@ -200,16 +200,84 @@
 wrap%22),%0A
+  order = require(%22gulp-order%22),%0A  uglify = require(%22gulp-uglify%22),%0A
   isDist
@@ -793,16 +793,36 @@
 cripts',
+ %5B'autopolyfiller'%5D,
  functio
@@ -861,16 +861,128 @@
 *.js'%5D)%0A
+    .pipe(order(%5B%0A      'src/heartbeat.js',%0A      'src/polyfills.js',%0A    %5D))%0A    .pipe(concat('heartbeat.js'))%0A
     .pip
@@ -1044,42 +1044,8 @@
 '))%0A
-    .pipe(concat('heartbeat.js'))%0A
     
@@ -1267,11 +1267,161 @@
 cripts'%5D
+, function() %7B%0A  return gulp.src(%5B'./dist/heartbeat.js'%5D)%0A    .pipe(uglify())%0A    .pipe(concat('heartbeat.min.js'))%0A    .pipe(gulp.dest('./dist/'));%0A%7D
 );%0A

Add build task