compile-minified.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # Copyright 2017 Google Inc. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ==============================================================================
  16. # This file builds all of the Javascript into a minified "hermetic" bundle.js
  17. # file, which is written out into the same directory as this script.
  18. #
  19. # This script takes no arguments. See README.md for more information.
  20. viz_path="$(readlink -f "$(dirname "$0")")"
  21. (
  22. cd "${viz_path}"
  23. docker build -t dragnn-viz-dev .
  24. )
  25. # Webpack is configured to write the bundle.js back out to code/src, which will
  26. # end up writing it to the Docker volume (and hence to the host filesystem).
  27. docker run --rm -ti \
  28. -v "${viz_path}:/code/src" \
  29. dragnn-viz-dev \
  30. ./node_modules/.bin/webpack --optimize-minimize
  31. mv "${viz_path}/bundle.js" "${viz_path}/viz.min.js"
  32. gzip -9 --force "${viz_path}/viz.min.js"
  33. echo "Compressed size: $(wc -c < "${viz_path}/viz.min.js.gz") bytes"