fix minifier generating malformed content

This commit is contained in:
mappu 2017-02-06 13:44:56 +13:00
parent e2af839101
commit 3f1f575652
1 changed files with 6 additions and 9 deletions

View File

@ -30,21 +30,18 @@ if (is_dir('clientpack')) {
// 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);
$html_content = preg_replace_callback('~<link[^>]+dcwebui.css[^>]*>~', function() { return '<style type="text/css">'.file_get_contents('clientpack/dcwebui.min.css').'</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);
$html_content = preg_replace_callback('~<script[^>]+dcwebui.js[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/dcwebui.min.js').'</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);
define('SIO_NAME', 'socket.io-1.7.2.js');
$html_content = preg_replace_callback('~<script[^>]+'.SIO_NAME.'[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/'.SIO_NAME).'</script>'; }, $html_content);
// Minify the combined file
@ -55,5 +52,5 @@ file_put_contents('clientpack/index.htm', $html_content);
// Clean up files
`rm clientpack/{index.htm,dcwebui{.min,}.js,dcwebui{.min,}.css}`;
unlink('clientpack/'.$SIO_NAME);
unlink('clientpack/'.SIO_NAME);
rename('clientpack/index.min.htm', 'clientpack/index.htm');