Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by granted on 3/5/15.
  3.  */
  4. var gulp = require('gulp');
  5. var uglify = require('gulp-uglify');
  6. var source = require('vinyl-source-stream');
  7. var browserify = require('browserify');
  8. var watchify = require('watchify');
  9. var reactify = require('reactify');
  10. var streamify = require('gulp-streamify');
  11.  
  12. var path = {
  13.     OUT: 'build.js',
  14.     VENDOR: 'vendor.js',
  15.     DEST_SRC: 'public/js',
  16.     ENTRY_POINT: './src/app/App.jsx'
  17. };
  18.  
  19. var dependencies = [
  20.     'react',
  21.     'react-router',
  22.     'react-bootstrap',
  23.     'react-router-bootstrap'
  24. ];
  25.  
  26. var buildTask = function(options) {
  27.     var watcher  = browserify({
  28.         entries: [path.ENTRY_POINT],
  29.         transform: [reactify],
  30.         debug: options.development,
  31.         cache: {}, packageCache: {}, fullPaths: true
  32.     });
  33.  
  34.     watcher.external(dependencies);
  35.  
  36.     var updater = function() {
  37.         console.log('Build');
  38.         if (options.development) {
  39.             watcher
  40.                 .bundle()
  41.                 .pipe(source(path.OUT))
  42.                 .pipe(gulp.dest(path.DEST_SRC))
  43.             ;
  44.         } else {
  45.             watcher
  46.                 .bundle()
  47.                 .pipe(source(path.OUT))
  48.                 .pipe(streamify(uglify()))
  49.                 .pipe(gulp.dest(path.DEST_SRC))
  50.         }
  51.     };
  52.     if (options.development) {
  53.         watcher = watchify(watcher);
  54.         watcher.on('update', updater);
  55.     }
  56.     updater();
  57.  
  58.     var vendorsBundler = browserify({
  59.         debug: true,
  60.         require: dependencies
  61.     });
  62.     vendorsBundler
  63.         .bundle()
  64.         .pipe(source(path.VENDOR))
  65.         .pipe(streamify(uglify()))
  66.         .pipe(gulp.dest(path.DEST_SRC))
  67. };
  68.  
  69. gulp.task('watch', function() {
  70.     buildTask({
  71.         development: true
  72.     });
  73. });
  74. gulp.task('deploy', function(){
  75.     buildTask({
  76.         development: false
  77.     })
  78. });
  79.  
  80. gulp.task('default', ['watch']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement