This has been concerning me for a while as such code included is not modular and completely not all needed apart from the mesh basic shaders and its includes ?
I have managed to bring three.js down another 150kb to 250kb. that is how much the shaders increases it.
I have figured out a way to append empty strings for the shaders not required in the bundler like this. This is being passed through for every single file though so slow.
function glsl() {
return {
transform( code, id ) {
if ( /\.glsl$/.test( id ) === false ) return;
if (!/meshbasic/.test(id)) {
return {
code: 'export default " "',
map: { mappings: '' }
};
}
var transformedCode = 'export default ' + JSON.stringify(
code
.replace( /[ \t]*\/\/.*\n/g, '' )
.replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' )
.replace( /\n{2,}/g, '\n' )
) + ';';
return {
code: transformedCode,
map: { mappings: '' }
};
}
};
}