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:
committed by
GitHub
parent
aefcb1176a
commit
c89daf6bf1
@@ -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};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user