@@ -61,6 +61,7 @@ public static class BuildScript
6161
6262 private static BuildPlayerOptions buildPlayerOptions ;
6363 private static List < string > errorLogMessages = new List < string > ( ) ;
64+ private static bool isSubmoduleStrippingEnabled = false ;
6465
6566 [ UsedImplicitly ]
6667 public static void BuildWithCommandlineArgs ( )
@@ -208,18 +209,17 @@ private static void HandleTagParameters(string tagVersion, NamedBuildTarget name
208209 private static void HandleSubmoduleStrippingParameters ( string [ ] tagParameters )
209210 {
210211#if UNITY_6000_1_OR_NEWER
211- bool enableStripping = tagParameters . Contains ( "minsize" ) || tagParameters . Contains ( "stripping" ) ;
212- PlayerSettings . WebGL . enableSubmoduleStrippingCompatibility = enableStripping ;
212+ isSubmoduleStrippingEnabled = tagParameters . Contains ( "minsize" ) || tagParameters . Contains ( "stripping" ) ;
213+ PlayerSettings . WebGL . enableSubmoduleStrippingCompatibility = isSubmoduleStrippingEnabled ;
213214
214- if ( enableStripping )
215+ if ( isSubmoduleStrippingEnabled )
215216 {
216217 PlayerSettings . WebGL . debugSymbolMode = WebGLDebugSymbolMode . Embedded ;
217218 }
218- StrippingProjectSettings . StripAutomaticallyAfterBuild = enableStripping ;
219- Log ( "Web submodule stripping is set to " + enableStripping ) ;
220219#else
221- Log ( "Skipping Web submodule stripping since is not supported in this Unity version" ) ;
220+ isSubmoduleStrippingEnabled = false ;
222221#endif
222+ Log ( $ "Web submodule stripping is set to { isSubmoduleStrippingEnabled } ") ;
223223 }
224224
225225 private static void SetGraphicsApi ( string [ ] tagParameters )
@@ -381,6 +381,33 @@ private static void Build(BuildTarget buildTarget, string filePath)
381381
382382 BuildSummary buildSummary = BuildPipeline . BuildPlayer ( buildPlayerOptions ) . summary ;
383383 ReportSummary ( buildSummary ) ;
384+
385+ #if UNITY_6000_1_OR_NEWER
386+ if ( buildTarget == BuildTarget . WebGL && isSubmoduleStrippingEnabled )
387+ {
388+ if ( buildSummary . result == BuildResult . Succeeded )
389+ {
390+ Log ( "Run Submodule Stripping for WebGL build..." ) ;
391+ var webBuild = WebBuildReportList . Instance . GetBuild ( buildSummary . outputPath ) ;
392+
393+ var settings = StrippingProjectSettings . ActiveSettings ;
394+ var successfulStripping = WebBuildProcessor . StripBuild ( webBuild , settings ) ;
395+ if ( successfulStripping )
396+ {
397+ Log ( "The build was stripped successfully." ) ;
398+ }
399+ else
400+ {
401+ LogError ( "Failed to strip the build." ) ;
402+ }
403+ }
404+ else
405+ {
406+ LogWarning ( "Skipping WebGL submodule stripping, since build failed." ) ;
407+ }
408+ }
409+ #endif
410+
384411 ExitWithResult ( buildSummary . result ) ;
385412 }
386413
0 commit comments