Skip to content

Commit 195928f

Browse files
rmarsigliclaude
andcommitted
build(sdk): add minification pipeline
Phase 3: Build & Minification (1.5h) - Created build.sh script using terser - Minify stub.js to stub.min.js (499 bytes gzipped) - Minify rush.js to rush.min.js (1,123 bytes gzipped) - Size report with original/minified/gzipped metrics - Validation warnings if sizes exceed targets - Both files meet performance targets Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f0c1933 commit 195928f

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

sdk/build.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🔨 Building Rush Analytics SDK..."
5+
echo ""
6+
7+
# Check dependencies
8+
if ! command -v npx &> /dev/null; then
9+
echo "❌ Error: npx not found. Install Node.js first."
10+
exit 1
11+
fi
12+
13+
# Create dist directory
14+
mkdir -p sdk/dist
15+
16+
# 1. Minify stub
17+
echo "📦 Minifying stub..."
18+
npx terser sdk/stub.js \
19+
--compress \
20+
--mangle \
21+
--output sdk/dist/stub.min.js
22+
23+
# 2. Minify full SDK
24+
echo "📦 Minifying full SDK..."
25+
npx terser sdk/rush.js \
26+
--compress \
27+
--mangle \
28+
--output sdk/dist/rush.min.js
29+
30+
# 3. Generate size report
31+
echo ""
32+
echo "📊 Size Report:"
33+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
34+
35+
# Stub sizes
36+
stub_original=$(wc -c < sdk/stub.js)
37+
stub_minified=$(wc -c < sdk/dist/stub.min.js)
38+
gzip -c sdk/dist/stub.min.js > /tmp/stub.min.js.gz
39+
stub_gzipped=$(wc -c < /tmp/stub.min.js.gz)
40+
rm /tmp/stub.min.js.gz
41+
42+
echo "Stub (inline):"
43+
echo " Original: ${stub_original} bytes"
44+
echo " Minified: ${stub_minified} bytes"
45+
echo " Gzipped: ${stub_gzipped} bytes"
46+
47+
# SDK sizes
48+
sdk_original=$(wc -c < sdk/rush.js)
49+
sdk_minified=$(wc -c < sdk/dist/rush.min.js)
50+
gzip -c sdk/dist/rush.min.js > /tmp/rush.min.js.gz
51+
sdk_gzipped=$(wc -c < /tmp/rush.min.js.gz)
52+
rm /tmp/rush.min.js.gz
53+
54+
echo ""
55+
echo "Full SDK (external):"
56+
echo " Original: ${sdk_original} bytes"
57+
echo " Minified: ${sdk_minified} bytes"
58+
echo " Gzipped: ${sdk_gzipped} bytes"
59+
60+
echo ""
61+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
62+
63+
# Validate sizes
64+
if [ $stub_gzipped -gt 600 ]; then
65+
echo "⚠️ Warning: Stub is ${stub_gzipped} bytes (target: <500 bytes)"
66+
fi
67+
68+
if [ $sdk_gzipped -gt 2500 ]; then
69+
echo "⚠️ Warning: SDK is ${sdk_gzipped} bytes (target: <2KB)"
70+
fi
71+
72+
echo ""
73+
echo "✅ Build complete!"
74+
echo ""
75+
echo "📂 Output files:"
76+
echo " sdk/dist/stub.min.js (copy to HTML)"
77+
echo " sdk/dist/rush.min.js (upload to CDN)"

sdk/dist/rush.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/dist/stub.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)