public static byte[] GetSerializedScript(string resourceName, BaristaContext context, bool mapWindowToGlobal = false) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(s_serializedScripts.GetOrAdd(resourceName, new Func <string, byte[]>((name) => { var script = EmbeddedResourceHelper.LoadResource(name); string mapWindowToGlobalString = mapWindowToGlobal ? "const window = global;" : null; var scriptWithModuleWrapper = $@"(() => {{ 'use strict'; {mapWindowToGlobalString} const module = {{ exports: {{}} }}; let exports = module.exports; {script} return module.exports; }})();"; return context.SerializeScript(scriptWithModuleWrapper); }))); }