From 0a46dc16a6a2725b22986bace15a9785d33e783d Mon Sep 17 00:00:00 2001
From: Berkeley Martinez <Berkeley@robotie.com>
Date: Wed, 11 Nov 2015 13:29:33 -0800
Subject: [PATCH] Fix for vendor files not working correctly with manifest

---
 .gitignore        |  1 +
 gulpfile.js       | 39 ++++++++++++---------------------------
 package.json      |  7 ++-----
 webpack.config.js |  3 +++
 4 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0f96fb3..a59cd15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,6 +44,7 @@ public/js/commonFramework*
 public/js/sandbox*
 public/js/iFrameScripts*
 public/js/plugin*
+public/js/vendor*
 public/css/main*
 
 server/rev-manifest.json
diff --git a/gulpfile.js b/gulpfile.js
index 5218705..22e7905 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -19,7 +19,7 @@ var Rx = require('rx'),
   merge = require('merge-stream'),
 
   // react app
-  webpack = require('gulp-webpack'),
+  webpack = require('webpack-stream'),
   webpackConfig = require('./webpack.config.js'),
   webpackConfigNode = require('./webpack.config.node.js'),
 
@@ -356,40 +356,25 @@ function getFilesGlob(files) {
   });
 }
 
-gulp.task('vendor', ['js'], function() {
+gulp.task('js', function() {
   var manifestName = 'js-manifest.json';
   var dest = paths.publicJs;
 
-  var vendorFiles = merge(
+  var jsFiles = merge(
+
     gulp.src(getFilesGlob(paths.vendorMain))
       .pipe(concat('vendor-main.js')),
+
     gulp.src(paths.vendorChallenges)
       .pipe(__DEV__ ? gutil.noop() : uglify())
-      .pipe(concat('vendor-challenges.js'))
-  );
+      .pipe(concat('vendor-challenges.js')),
 
-  return vendorFiles.pipe(gulp.dest(dest))
-    // create registry file
-    .pipe(rev())
-    // copy revisioned assets to dest
-    .pipe(gulp.dest(dest))
-    // create manifest file
-    .pipe(rev.manifest(manifestName))
-    .pipe(delRev(
-      dest,
-      manifestName
-    ))
-    // copy manifest file to dest
-    .pipe(gulp.dest(paths.manifest));
-});
-
-gulp.task('js', function() {
-  var manifestName = 'js-manifest.json';
-  var dest = paths.publicJs;
+    gulp.src(paths.js)
+      .pipe(plumber({ errorHandler: errorHandler }))
+      .pipe(__DEV__ ? gutil.noop() : uglify())
+  );
 
-  return gulp.src(paths.js)
-    .pipe(plumber({ errorHandler: errorHandler }))
-    .pipe(__DEV__ ? gutil.noop() : uglify())
+  return jsFiles
     .pipe(gulp.dest(dest))
     // create registry file
     .pipe(rev())
@@ -444,7 +429,7 @@ function buildManifest() {
     .pipe(gulp.dest('server/'));
 }
 
-var buildDependents = ['less', 'js', 'dependents', 'vendor'];
+var buildDependents = ['less', 'js', 'dependents'];
 
 gulp.task('build-manifest', buildDependents, function() {
   return buildManifest();
diff --git a/package.json b/package.json
index 21138d1..cd71221 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
     "create-rev": "test ! -e server/rev-manifest.json && echo '\n\ncreating manifest\n\n' && touch server/rev-manifest.json && echo '{}' >> server/rev-manifest.json",
     "build": "NODE_ENV=production gulp build -p",
     "start": "babel-node server/server.js",
-    "prestart-production": "bower cache clean && bower install && gulp build",
+    "prestart-production": "bower cache clean && bower install && gulp build -p",
     "start-production": "node pm2Start",
     "lint": "npm run lint-js && npm run lint-json",
     "lint-challenges": "jsonlint -q seed/challenges/*.json",
@@ -122,12 +122,9 @@
     "url-regex": "^3.0.0",
     "validator": "^4.2.1",
     "webpack": "^1.9.12",
+    "webpack-stream": "^2.1.1",
     "xss-filters": "^1.2.6",
-<<<<<<< HEAD
     "yargs": "^3.30.0"
-=======
-    "yargs": "^3.29.0"
->>>>>>> bundle vendor files
   },
   "devDependencies": {
     "blessed": "~0.1.81",
diff --git a/webpack.config.js b/webpack.config.js
index 3e4c424..6069bb9 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,3 +1,4 @@
+var webpack = require('webpack');
 var path = require('path');
 var webpack = require('webpack');
 
@@ -31,6 +32,8 @@ module.exports = {
     ]
   },
   plugins: [
+    new webpack.optimize.DedupePlugin(),
+    new webpack.optimize.OccurenceOrderPlugin(true),
     new webpack.DefinePlugin({
       'process.env': {
         'NODE_ENV': JSON.stringify(__DEV__ ? 'development' : 'production')
