Repository: oppia/oppia

Issue:
Add only build third_party.min.js option to build.py
We run frontend tests for dev and prod server. The main difference is that prod run of frontend tests use the minified version of third_party.js. Currently, when we run prod frontend tests we run the whole build process (build minified third_party.js, add hashes to filenames, add hashes to HTML, etc.), we should create an option in build.py to only build minified third_party.js and the call just that before the prod frontend tests.



Discussion:
Ah, now I get it, thanks @vojtechjelinek for explaining.

When devs submit code to github, do the presubmit checks that run on the dev's local machine run frontend tests in dev or prod mode? If the latter, then this becomes more important to fix since all the hash stuff takes a long time.
Just dev mode.
ok, good to know. Thanks!
@vojtechjelinek are you still working on this?
De-assigning for now. Please re-assign if you'd like to resume work.
Assigning to myself. If any one is already working on this please let me know. Thanks!
@sshou14 are you working on this? If not I would like to take this up
@lilithxxx Hi Rishav, I'm already working on this, could you pick another issue? Thanks!
Yes sure good luck :) 
Just to make sure my understanding is correct..
The reason we hash files is to determine whether they've changed, so that we may need to rebuild them?
And we don't want to do this for prod tests because we are assuming no file has been changed since they get pushed?

Resolving patch:
diff --git a/scripts/build.py b/scripts/build.py
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -1043,8 +1043,6 @@ def generate_build_directory():
     hashes = dict()
     build_tasks = collections.deque()
     copy_tasks = collections.deque()
-    # Minify third party resources.
-    minify_third_party_libs(THIRD_PARTY_GENERATED_DEV_DIR)
 
     # Create hashes for all directories and files.
     HASH_DIRS = [
@@ -1102,12 +1100,23 @@ def build():
     parser = optparse.OptionParser()
     parser.add_option(
         '--prod_env', action='store_true', default=False, dest='prod_mode')
+    parser.add_option(
+        '--minify_third_party_libs_only', action='store_true', default=False,
+        dest='minify_third_party_libs_only')
     options = parser.parse_args()[0]
     # Regenerate /third_party/generated from scratch.
     safe_delete_directory_tree(THIRD_PARTY_GENERATED_DEV_DIR)
     build_third_party_libs(THIRD_PARTY_GENERATED_DEV_DIR)
+
+    # If minify_third_party_libs_only is set to True, skips the rest of the
+    # build process once third party libs are minified.
+    if options.minify_third_party_libs_only and not options.prod_mode:
+        raise Exception(
+            'minify_third_party_libs_only should not be set in non-prod mode.')
     if options.prod_mode:
-        generate_build_directory()
+        minify_third_party_libs(THIRD_PARTY_GENERATED_DEV_DIR)
+        if not options.minify_third_party_libs_only:
+            generate_build_directory()
 
 
 if __name__ == '__main__':


Test patch:
diff --git a/scripts/run_frontend_tests.sh b/scripts/run_frontend_tests.sh
--- a/scripts/run_frontend_tests.sh
+++ b/scripts/run_frontend_tests.sh
@@ -69,7 +69,7 @@ if [ "$RUN_MINIFIED_TESTS" = "true" ]; then
   echo ""
   echo "  Running test in production environment"
   echo ""
-  $PYTHON_CMD scripts/build.py --prod_env
+  $PYTHON_CMD scripts/build.py --prod_env --minify_third_party_libs_only
   $XVFB_PREFIX $NODE_MODULE_DIR/karma/bin/karma start core/tests/karma.conf.js --prod_env=True
 fi