Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. var gulp = require('gulp');
  2. var gutil = require('gulp-util');
  3. var guglify = require('gulp-uglify');
  4. var source = require('vinyl-source-stream');
  5. var buffer = require('vinyl-buffer');
  6. var browserify = require('browserify');
  7. var watchify = require('watchify');
  8. var babelify = require('babelify');
  9.  
  10. var colors = {
  11. success : gutil.colors.green,
  12. error : gutil.colors.bgRed.bold,
  13. info : gutil.colors.cyan,
  14. };
  15.  
  16. function compile(watch) {
  17. var ts = colors.info('Bundled') + ' main.js';
  18. var bundler = browserify('./main.js', { debug: true })
  19. .transform(babelify.configure({
  20. comments: false,
  21. }));
  22.  
  23. if (watch) {
  24. bundler = watchify(bundler);
  25. bundler.on('update', () => {
  26. console.log('Recompiling');
  27. rebundle();
  28. });
  29. }
  30.  
  31. function rebundle() {
  32. console.time(ts);
  33. return bundler.bundle()
  34. .on('error', (err) => gutil.log(colors.error('Error:'), err))
  35. .on('end', () => console.timeEnd(ts))
  36. .pipe(source('main.js'))
  37. .pipe(buffer())
  38. .pipe(guglify({ compress: true }))
  39. .pipe(gulp.dest('./dist'));
  40. }
  41.  
  42. return rebundle();
  43. }
  44.  
  45. function watch() {
  46. return compile(true);
  47. };
  48.  
  49. gulp.task('build', () => compile());
  50. gulp.task('watch', () => watch());
  51.  
  52. gulp.task('default', ['build']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement