maraf / dotnet-wasm-rename-icu

Change extension of ICU files in .NET on WASM app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotnet-wasm-rename-icu

Change extension of ICU files in .NET on WASM app

Live demo

https://maraf.github.io/dotnet-wasm-rename-icu/

Building source code

  • Install .NET 8 SDK (RC1)
  • Install wasm-tools workload dotnet workload install wasm-tools
  • Run the project dotnet run

Keep eye on

The solution consists of two parts

MSBuild

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    ...

    <!-- πŸ‘‡ New extension for ICU files -->
    <NewIcuFileExtension>.icu</NewIcuFileExtension>
  </PropertyGroup>

  ...

  <!-- πŸ‘‡ After the application is build/published -->
  <Target Name="RenameIcuToAppBundle" AfterTargets="WasmBuildApp;WasmNestedPublishApp">
    <ItemGroup>
      <!-- πŸ‘‡ Find all ICU files in AppBundle -->
      <IcuFiles Include="$(WasmAppDir)\**\*.dat" />
    </ItemGroup>

    <!-- πŸ‘‡ Change their extension to 'NewIcuFileExtension' -->
    <Move SourceFiles="@(IcuFiles)"
      OverwriteReadOnlyFiles="true"
      DestinationFiles="%(RelativeDir)%(Filename)$(NewIcuFileExtension)" />
  </Target>
</Project>

Javascript

... = await dotnet
    // πŸ‘‡ Override resource URL resolution
    .withResourceLoader((type, name, defaultUri, integrity) => {
          // πŸ‘‡ Override extension of ICU files
          if (type == 'globalization') {
              defaultUri = defaultUri.replace('.dat', '.icu');
          }

          return defaultUri;
      })
    .create();

About

Change extension of ICU files in .NET on WASM app

License:Apache License 2.0


Languages

Language:JavaScript 43.8%Language:C# 37.1%Language:HTML 19.1%