client: minify/combine CSS/JS/HTML via extra build step
This commit is contained in:
parent
692537c6f0
commit
1a64f79394
@ -2,6 +2,7 @@ mode:regex
|
||||
|
||||
\.exe$
|
||||
^nmdc-webfrontend\.conf$
|
||||
^clientpack/
|
||||
|
||||
^_dist/
|
||||
^bindata\.go$
|
5
build.sh
5
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"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* dcwebui.js */
|
||||
//;(function() {
|
||||
//IIFEMODE:;(function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
@ -1144,4 +1144,4 @@ window.onload = function() {
|
||||
});
|
||||
};
|
||||
|
||||
//})();
|
||||
//IIFEMODE:})();
|
||||
|
59
clientpack.php
Normal file
59
clientpack.php
Normal file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
# Dependencies:
|
||||
# - PHP
|
||||
# - Uglifyjs (`npm install -g uglifyjs`)
|
||||
# - Lessc (`npm install -g less`)
|
||||
# - Lessc minifier (`npm install -g less-plugin-clean-css`)
|
||||
# - HTML minifier (`npm install -g html-minifier`)
|
||||
|
||||
echo "Compressing/minifying web resources...\n";
|
||||
|
||||
if (is_dir('clientpack')) {
|
||||
`rm -r clientpack`;
|
||||
}
|
||||
|
||||
`cp -r client clientpack`;
|
||||
|
||||
// Toggle IIFE on
|
||||
|
||||
`sed -i -re 's~//IIFEMODE:~~g' clientpack/dcwebui.js`;
|
||||
|
||||
// Minify JS
|
||||
|
||||
`uglifyjs clientpack/dcwebui.js -o clientpack/dcwebui.min.js -c -m`;
|
||||
|
||||
// Minify CSS
|
||||
|
||||
`lessc --clean-css clientpack/dcwebui.css clientpack/dcwebui.min.css`;
|
||||
|
||||
// Embed css into HTML file
|
||||
|
||||
$css_file = file_get_contents('clientpack/dcwebui.min.css');
|
||||
|
||||
$html_content = file_get_contents('clientpack/index.htm');
|
||||
$html_content = preg_replace('~<link[^>]+dcwebui.css[^>]*>~', '<style type="text/css">'.$css_file.'</style>', $html_content);
|
||||
|
||||
// Embed JS into HTML file
|
||||
|
||||
$js_file = file_get_contents('clientpack/dcwebui.min.js');
|
||||
$html_content = preg_replace('~<script[^>]+dcwebui.js[^>]*>~', '<script type="text/javascript">'.$js_file.'</script>', $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('~<script[^>]+'.$SIO_NAME.'[^>]*>~', '<script type="text/javascript">'.$sio_file.'</script>', $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');
|
Loading…
Reference in New Issue
Block a user