Apr
7
2021

Compress WebGL build manually from command line (brotli)

Building brotli compressed webgl release can take hours (if you have large 3d models in the project..), and you cannot do anything with the project while unity is compressing it.

Solution:
Make (really fast) uncompressed builds from unity,
then compress the webgl data files manually from commandline!
(note that the example script below uses absolute paths for Unity 2019.4 and project folder)

echo off
REM add egg path
set PYTHONPATH=D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Brotli/dist/Brotli-0.4.0-py2.7-win-amd64.egg
REM rename uncompressed data files (because brotli cannot overwrite same file that its packing)
move /Y "F:\Your\Project\Build\uncompressed.wasm.framework.unityweb" "F:\Your\Project\Build\uncompressed.wasm.framework.unityweb2"
move /Y "F:\Your\Project\Build\uncompressed.wasm.code.unityweb" "F:\Your\Project\Build\uncompressed.wasm.code.unityweb2"
move /Y "F:\Your\Project\Build\uncompressed.data.unityweb" "F:\Your\Project\Build\uncompressed.data.unityweb2"
REM compress
"D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" "D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Brotli\python\bro.py" -o "F:\Your\Project\Builds\uncompressed\Build\uncompressed.wasm.framework.unityweb2" -i "F:\Your\Project\Builds\\uncompressed\Build\uncompressed.wasm.framework.unityweb" –comment "UnityWeb Compressed Content (brotli)"
"D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" "D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Brotli\python\bro.py" -o "F:\Your\Project\Builds\\uncompressed\Build\uncompressed.wasm.code.unityweb2" -i "F:\Your\Project\Builds\\uncompressed\Build\uncompressed.wasm.code.unityweb" –comment "UnityWeb Compressed Content (brotli)"
"D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" "D:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Brotli\python\bro.py" -o "F:\Your\Project\Builds\\uncompressed\Build\uncompressed.data.unityweb2" -i "F:\Your\Project\Builds\\uncompressed\Build\uncompressed.data.unityweb" –comment "UnityWeb Compressed Content (brotli)"

Some notes:
– Script renames uncompressed data files first as *.unityweb2, because brotli cannot overwrite the same files that its compressing (optionally you could keep original file names, and create new compressed filenames, and modify the .json file to use new compressed files instead)
– need to add that brotli .egg path into pythonpath, otherwise bro.py cannot find it (optionally you could modify .bro file to include that path directly, see image below, modified script header to include path:


1 Comment + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.