Skip to content

Commit

Permalink
Merge pull request #161 from yoshuawuyts/better-build
Browse files Browse the repository at this point in the history
script/build: prune the prod builds
  • Loading branch information
yoshuawuyts authored Jul 12, 2016
2 parents d7f614d + ed384bc commit 701dec4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@
"browserify-istanbul": "^2.0.0",
"bundle-collapser": "^1.2.1",
"dependency-check": "^2.5.1",
"disc": "^1.3.2",
"envify": "^3.4.1",
"es2020": "^1.0.1",
"geval": "~2.1.1",
"gzip-size-cli": "^1.0.0",
"insert-css": "^0.2.0",
"istanbul": "^0.4.4",
"karma-sauce-launcher": "^1.0.0",
"min-document": "~2.18.0",
"pretty-bytes-cli": "^1.0.0",
"proxyquire": "~1.7.10",
"proxyquire-universal": "~1.0.8",
"proxyquireify": "~3.2.0",
Expand Down
7 changes: 7 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ build_dev () {
NODE_ENV=development "$browserify" index.js \
--standalone=choo \
-t envify \
-g yo-yoify \
-g es2020 \
> dist/choo.js
}

Expand All @@ -23,7 +25,12 @@ build_min () {
--standalone=choo \
-t envify \
-g unassertify \
-g yo-yoify \
-g es2020 \
-g uglifyify \
-t envify \
-p bundle-collapser/plugin \
| uglifyjs \
| "$uglify" \
> dist/choo.min.js
}
Expand Down
41 changes: 31 additions & 10 deletions scripts/instrument
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

dirname=$(dirname "$(readlink -f "$0")")

browserify="$dirname/../node_modules/.bin/browserify"
uglify="$dirname/../node_modules/.bin/uglifyjs"
pretty_bytes="$dirname/../node_modules/.bin/pretty-bytes"
gzip_size="$dirname/../node_modules/.bin/gzip-size"
discify="$dirname/../node_modules/.bin/discify"

usage () {
cat << USAGE
script/test-size
Expand All @@ -10,38 +18,51 @@ script/test-size
USAGE
}

# use zopfli for better compression if available
gzip () {
zopfli -h 2>/dev/null
if [ $? -eq 0 ]; then
zopfli "$1" -i1000 -c | wc -c
else
"$gzip_size" < "$1"
fi
}

gzip_size () {
browserify index.js \
mkdir -p tmp/
"$browserify" index.js \
-g unassertify \
-g yo-yoify \
-g es2020 \
-g uglifyify \
-p bundle-collapser/plugin \
| uglifyjs \
| gzip-size \
| pretty-bytes
| "$uglify" \
> tmp/bundle.min.js

gzip tmp/bundle.min.js | "$pretty_bytes"
rm -rf tmp/
}

min_size () {
browserify index.js \
"$browserify" index.js \
-g unassertify \
-g yo-yoify \
-g es2020 \
-g uglifyify \
-p bundle-collapser/plugin \
| uglifyjs \
| "$uglify" \
| wc -c \
| pretty-bytes
| "$pretty_bytes"
}

run_discify () {
browserify index.js --full-paths \
"$browserify" index.js --full-paths \
-g unassertify \
-g yo-yoify \
-g es2020 \
-g uglifyify \
| uglifyjs \
| discify --open
| "$uglify" \
| "$discify" --open
}

# set CLI flags
Expand Down

0 comments on commit 701dec4

Please sign in to comment.