Skip to content

Instantly share code, notes, and snippets.

@nichoth
Created August 28, 2016 22:20
Show Gist options
  • Save nichoth/e22ee4a4c210195c01ca0009f987111a to your computer and use it in GitHub Desktop.
Save nichoth/e22ee4a4c210195c01ca0009f987111a to your computer and use it in GitHub Desktop.
Browserify build example (taken from choo)
#!/bin/sh
usage () {
printf "Usage: build-umd <argument>\n"
}
# use zopfli for better compression if available
gzip () {
zopfli -h 2>/dev/null
if [ $? -eq 0 ]; then
zopfli "$1" -i1000 -c
else
gzip -c "$1"
fi
}
build_dev () {
mkdir -p dist/
NODE_ENV=development browserify index.js \
--standalone=choo \
-t envify \
-g yo-yoify \
-g es2020 \
> dist/choo.js
NODE_ENV=development browserify html.js \
--standalone=html \
> dist/html.js
}
build_min () {
mkdir -p dist/
NODE_ENV=production browserify index.js \
--standalone=choo \
-t envify \
-g unassertify \
-g yo-yoify \
-g es2020 \
-g uglifyify \
-t envify \
-p bundle-collapser/plugin \
| uglifyjs \
> dist/choo.min.js
NODE_ENV=production browserify html.js \
--standalone=html \
> dist/html.min.js
}
build_gz () {
build_min
gzip dist/choo.min.js > dist/choo.min.js.gz
cp dist/choo.min.js.gz dist/choo.gz
}
# parse CLI flags
while true; do
case "$1" in
-h|--help) usage && exit 1 ;;
-- ) shift; break ;;
* ) break ;;
esac
done
case "$1" in
d|dev) shift; build_dev "$@" ;;
m|min) shift; build_min "$@" ;;
g|gzip) shift; build_gz "$@" ;;
*) shift; build_min "$@" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment