From 1a64f793942374c4145136de84007feb5f23abae Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 6 Feb 2017 11:58:38 +1300 Subject: [PATCH] client: minify/combine CSS/JS/HTML via extra build step --- .hgignore | 1 + build.sh | 5 ++-- client/dcwebui.js | 4 ++-- clientpack.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 clientpack.php diff --git a/.hgignore b/.hgignore index f487dbf..c9bab7f 100644 --- a/.hgignore +++ b/.hgignore @@ -2,6 +2,7 @@ mode:regex \.exe$ ^nmdc-webfrontend\.conf$ +^clientpack/ ^_dist/ ^bindata\.go$ \ No newline at end of file diff --git a/build.sh b/build.sh index 5e5bca8..f712a9f 100644 --- a/build.sh +++ b/build.sh @@ -158,8 +158,9 @@ main() { if [[ -f ./bindata.go ]] ; then rm ./bindata.go fi - go-bindata -nomemcopy -prefix client client - + php clientpack.php + go-bindata -nomemcopy -prefix clientpack clientpack + GOARCH=amd64 GOOS=windows single_build "$version" GOARCH=386 GOOS=windows single_build "$version" GOARCH=amd64 GOOS=linux single_build "$version" diff --git a/client/dcwebui.js b/client/dcwebui.js index b33a19e..933f9f2 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -1,5 +1,5 @@ /* dcwebui.js */ -//;(function() { +//IIFEMODE:;(function() { "use strict"; @@ -1144,4 +1144,4 @@ window.onload = function() { }); }; -//})(); +//IIFEMODE:})(); diff --git a/clientpack.php b/clientpack.php new file mode 100644 index 0000000..c5bbdf6 --- /dev/null +++ b/clientpack.php @@ -0,0 +1,59 @@ +#!/usr/bin/php +]+dcwebui.css[^>]*>~', '', $html_content); + +// Embed JS into HTML file + +$js_file = file_get_contents('clientpack/dcwebui.min.js'); +$html_content = preg_replace('~]+dcwebui.js[^>]*>~', '', $html_content); + +// Embed socketio into HTML file + +$SIO_NAME = 'socket.io-1.7.2.js'; +$sio_file = file_get_contents('clientpack/'.$SIO_NAME); +$html_content = preg_replace('~]+'.$SIO_NAME.'[^>]*>~', '', $html_content); + +// Minify the combined file + +file_put_contents('clientpack/index.htm', $html_content); + +`html-minifier --collapse-whitespace -o clientpack/index.min.htm clientpack/index.htm`; + +// Clean up files + +`rm clientpack/{index.htm,dcwebui{.min,}.js,dcwebui{.min,}.css}`; +unlink('clientpack/'.$SIO_NAME); +rename('clientpack/index.min.htm', 'clientpack/index.htm');