Created
July 23, 2025 04:07
-
-
Save mminer/c8709e4bb0c96ae19482704b780e9971 to your computer and use it in GitHub Desktop.
Unity build preprocessing script to enable Disk Size with LTO code optimization for WebGL builds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
using UnityEngine; | |
public class PreprocessBuild : IPreprocessBuildWithReport | |
{ | |
public int callbackOrder { get; } | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
Debug.Log("Preprocessing build."); | |
#if UNITY_WEBGL | |
// We only want to change user build settings for automated builds, not for local development. | |
// If we didn't check for batch mode, this would override the developer's preferred code optimization setting | |
// (which is probably "Shorter Build Time"). | |
if (Application.isBatchMode) | |
{ | |
Debug.Log("Setting WebGL code optimization to Disk Size with LTO."); | |
UnityEditor.WebGL.UserBuildSettings.codeOptimization = UnityEditor.WebGL.WasmCodeOptimization.DiskSizeLTO; | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment