Add basic shader minification (#13500)

* add basic shader minification (same GL JS does)

* don't remove line break at shader end
This commit is contained in:
Vladimir Agafonkin
2018-12-04 16:09:43 +02:00
committed by GitHub
parent aefcb1176a
commit c89daf6bf1
28 changed files with 957 additions and 1616 deletions

View File

@@ -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};
}