forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.sh
executable file
·28 lines (22 loc) · 1.05 KB
/
analyze.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
set -euo pipefail
ARTIFACT_DIR=${ARTIFACT_DIR:=/tmp/artifacts}
# Run `yarn analyze` and save the report as artifacts in CI.
cd frontend
echo "Analyzing Webpack bundles..."
yarn run analyze
if [ -d "$ARTIFACT_DIR" ]; then
echo "Copying the Webpack Bundle Analyzer report to $ARTIFACT_DIR..."
cp public/dist/report.html "${ARTIFACT_DIR}"
fi
MAX_BYTES=3670016 # ~3.5 MiB
VENDORS_MAIN_BYTES=$(du -b `find public/dist -type f -name 'vendors~main-chunk*js'` | cut -f1)
DISPLAY_VALUE=$(awk "BEGIN {printf \"%.2f\n\", $VENDORS_MAIN_BYTES/1024/1024}")
MAX_DISPLAY_VALUE=$(awk "BEGIN {printf \"%.2f\n\", $MAX_BYTES/1024/1024}")
echo "Main vendor bundle size: $DISPLAY_VALUE MiB"
if (( VENDORS_MAIN_BYTES > MAX_BYTES )); then
echo "FAILURE: Main vendor bundle is larger than the $MAX_DISPLAY_VALUE MiB limit."
echo "If you haven't added a new dependency, an import might have accidentally pulled an existing dependency into the main vendor bundle."
echo "If adding a large dependency, consider lazy loading the component with AsyncComponent."
exit 1
fi