Skip to content

[browser] Bundler friendly output #116300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jun 13, 2025
Merged

Conversation

maraf
Copy link
Member

@maraf maraf commented Jun 4, 2025

  • New boot config schema allowing us to attach more information to individual assets
    • Instead of using simple dictionary, we now have an array of objects
    • Integrity is exported only for files that use it
  • Module initializers now supports moduleExports instead of link to file as well
  • A new msbuild property WasmBundlerFriendlyBootConfig which enables to generate boot config, this is not working in browsers on it's own, but can be preprocessed by transpilers like babel. Using rollup or webpack it can be configured to (for example):
    • Resolve wasm & other files as files, copying them to the output directory, optionally fingerprinting them
    • Embed wasm & other files as base64 encoded blobs directly into the javascript
  • New Wasm.Build.Tests configuration running selected tests with WasmBundlerFriendlyBootConfig=true & repacking the publish output with rollup
    • To simplify the setup, it runs the tests only on publish output. Mainly because during build user files (eg main.js) aren't copied to the build output and so they can't be easily bundled into single file
    • CI is using npm installed into helix machines/docker images
    • Correct npm path resolution will be fixed in a follow-up
Sample boot config
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.

import * as dotnet_runtime_js from "./dotnet.runtime.js";
import * as dotnet_native_js from "./dotnet.native.js";
import dotnet_native_wasm from "./dotnet.native.wasm";
import System_Runtime_InteropServices_JavaScript_wasm from "./System.Runtime.InteropServices.JavaScript.wasm";
import System_Private_CoreLib_wasm from "./System.Private.CoreLib.wasm";
import System_Runtime_wasm from "./System.Runtime.wasm";
import RollupDotNet_wasm from "./RollupDotNet.wasm";
import * as __RollupDotNet_1uxdo6nju6_lib_module_js from "./../RollupDotNet.1uxdo6nju6.lib.module.js";
import * as ___2F_RollupDotNet_1uxdo6nju6_lib_module_js from "./../RollupDotNet.1uxdo6nju6.lib.module.js";
import ___2F_appsettings_json from "./../appsettings.json";

var WasmEnableThreads = false;

...

dotnet.withConfig(/*json-start*/{
  "mainAssemblyName": "RollupDotNet",
  "resources": {
    "hash": "sha256-6j4TfY4hqK2qKV90WC2cRVlNXjAaZ24ep5vJAmqiYrI=",
    "jsModuleNative": [
      {
        "name": "dotnet.native.js",
        "moduleExports": dotnet_native_js
      }
    ],
    "jsModuleRuntime": [
      {
        "name": "dotnet.runtime.js",
        "moduleExports": dotnet_runtime_js
      }
    ],
    "wasmNative": [
      {
        "name": "dotnet.native.wasm",
        "integrity": "sha256-M7SZyK2m4UwAOa84vukO1znsJ+yxlAxtSnpZKV+Z3ZI=",
        "resolvedUrl": dotnet_native_wasm
      }
    ],
    "coreAssembly": [
      {
        "virtualPath": "System.Runtime.InteropServices.JavaScript.wasm",
        "name": "System.Runtime.InteropServices.JavaScript.wasm",
        "integrity": "sha256-IdWvP/V/e1XXYvXDeG5pT3BwSL/VV5FtIC1AvIVNqDw=",
        "resolvedUrl": System_Runtime_InteropServices_JavaScript_wasm
      },
      {
        "virtualPath": "System.Private.CoreLib.wasm",
        "name": "System.Private.CoreLib.wasm",
        "integrity": "sha256-d+RzHESxTy3EAXcG7WPAGC5QfKO/+BlJnFQgtSxk3kg=",
        "resolvedUrl": System_Private_CoreLib_wasm
      }
    ],
    "assembly": [
      {
        "virtualPath": "System.Runtime.wasm",
        "name": "System.Runtime.wasm",
        "integrity": "sha256-RXtMA0t8B/vmiES29vtYhE7cqBD+j8spovTroyOaU4M=",
        "resolvedUrl": System_Runtime_wasm
      },
      {
        "virtualPath": "RollupDotNet.wasm",
        "name": "RollupDotNet.wasm",
        "integrity": "sha256-ADHfSUAIpH+Xnkhn9aGEPq0sBL+ZM2kM/lGZW7rK0ic=",
        "resolvedUrl": RollupDotNet_wasm
      }
    ],
    "libraryInitializers": [
      {
        "name": "RollupDotNet.1uxdo6nju6.lib.module.js",
        "moduleExports": __RollupDotNet_1uxdo6nju6_lib_module_js
      }
    ],
    "modulesAfterConfigLoaded": [
      {
        "name": "../RollupDotNet.1uxdo6nju6.lib.module.js",
        "moduleExports": ___2F_RollupDotNet_1uxdo6nju6_lib_module_js
      }
    ]
  },
  "debugLevel": 0,
  "linkerEnabled": true,
  "appsettings": [
    ___2F_appsettings_json
  ],
  "globalizationMode": "invariant",
  "runtimeConfig": {
    "runtimeOptions": {
      "configProperties": {
        ...
      }
    }
  }
}/*json-end*/);

Contributes to #77191
Fixes #86162

@maraf maraf added this to the 10.0.0 milestone Jun 4, 2025
@maraf maraf self-assigned this Jun 4, 2025
@maraf maraf added arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm labels Jun 4, 2025
Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment that should be addressed but LGTM otherwise

maraf and others added 4 commits June 13, 2025 12:44
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
@maraf maraf enabled auto-merge (squash) June 13, 2025 11:48
@maraf
Copy link
Member Author

maraf commented Jun 13, 2025

/ba-g Failures are not related

@maraf maraf merged commit 6df065d into dotnet:main Jun 13, 2025
91 of 99 checks passed
@maraf maraf deleted the BrowserBundlerFriendly branch June 13, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[browser] Provide "single-file" deployment
4 participants