diff --git a/package.json b/package.json index 212e1618..fcb93ad6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/build b/scripts/build index c99a8072..28c2f802 100755 --- a/scripts/build +++ b/scripts/build @@ -14,6 +14,8 @@ build_dev () { NODE_ENV=development "$browserify" index.js \ --standalone=choo \ -t envify \ + -g yo-yoify \ + -g es2020 \ > dist/choo.js } @@ -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 } diff --git a/scripts/instrument b/scripts/instrument index 123c132f..ced46c4e 100755 --- a/scripts/instrument +++ b/scripts/instrument @@ -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 @@ -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