summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorVladimir Agafonkin <agafonkin@gmail.com>2018-12-04 16:09:43 +0200
committerGitHub <noreply@github.com>2018-12-04 16:09:43 +0200
commitc89daf6bf190223b6da7867973d3f42f785eee01 (patch)
tree5c81a81ec1b32d77d6ce0afc5871dccf008f7cfb /scripts
parentaefcb1176a819c63d515cbf520ac4739cb05fcf7 (diff)
downloadqtlocation-mapboxgl-c89daf6bf190223b6da7867973d3f42f785eee01.tar.gz
Add basic shader minification (#13500)
* add basic shader minification (same GL JS does) * don't remove line break at shader end
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-shaders.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index a3246c92d9..78d8911839 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -13,14 +13,23 @@ require('./style-code');
let concatenated = '';
let offsets = {};
+function basicMinify(src) {
+ return src = src.trim() // strip whitespace at the start/end
+ .replace(/\s*\/\/[^\n]*\n/g, '\n') // strip double-slash comments
+ .replace(/\n+/g, '\n') // collapse multi line breaks
+ .replace(/\n\s+/g, '\n') // strip identation
+ .replace(/\s?([+-\/*=,])\s?/g, '$1') // strip whitespace around operators
+ .replace(/([;\(\),\{\}])\n(?=[^#])/g, '$1'); // strip more line breaks
+}
+
for (const key in shaders) {
const vertex = concatenated.length;
- concatenated += shaders[key].vertexSource;
- concatenated += '\0';
+ concatenated += basicMinify(shaders[key].vertexSource);
+ concatenated += '\n\0';
const fragment = concatenated.length;
- concatenated += shaders[key].fragmentSource;
- concatenated += '\0';
+ concatenated += basicMinify(shaders[key].fragmentSource);
+ concatenated += '\n\0';
offsets[key] = {vertex, fragment};
}