Skip to content
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

Write import map to html files #46233

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--
***********************************************************************************************
Microsoft.NET.Sdk.StaticWebAssets.targets

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->

<Project ToolsVersion="14.0">

<UsingTask TaskName="Microsoft.AspNetCore.StaticWebAssets.Tasks.WriteImportMapToHtml" AssemblyFile="$(StaticWebAssetsSdkBuildTasksAssembly)" />

<PropertyGroup>
<ResolveBuildRelatedStaticWebAssetsDependsOn>
$(ResolveStaticWebAssetsInputsDependsOn);
_UpdateHtmlFiles;
Copy link
Member

Choose a reason for hiding this comment

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

Note: This needs to happen also before the service-worker-manifest gets generated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is that? The html documents are not part of service worker assets manifest, aren't they?

</ResolveBuildRelatedStaticWebAssetsDependsOn>
<ResolveCompressedFilesDependsOn>
$(ResolveCompressedFilesDependsOn);
_UpdateHtmlFiles
</ResolveCompressedFilesDependsOn>
</PropertyGroup>
<ItemGroup>
<StaticWebAssetFingerprintPattern Include="Js" Pattern="*.js" Expression="#[.{fingerprint}]!" />
maraf marked this conversation as resolved.
Show resolved Hide resolved
<StaticWebAssetFingerprintPattern Include="Css" Pattern="*.css" Expression="#[.{fingerprint}]!" />
maraf marked this conversation as resolved.
Show resolved Hide resolved
maraf marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<Target Name="_UpdateHtmlFiles">
<PropertyGroup>
<_WasmBuildImportMapHtmlPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'importmaphtml', 'build'))</_WasmBuildImportMapHtmlPath>
maraf marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<MakeDir Directories="$(_WasmBuildImportMapHtmlPath)"/>

<!-- Find HTML swa -->
<ItemGroup>
<_HtmlStaticWebAssets Include="@(StaticWebAsset)" Condition="'%(Extension)' == '.html'" />
</ItemGroup>

<!-- Write import map and fingerprinted assets to html files -->
<WriteImportMapToHtml
Source="$(PackageId)"
ManifestType="Build"
Assets="@(StaticWebAsset)"
Endpoints="@(StaticWebAssetEndpoint)"
HtmlFiles="@(_HtmlStaticWebAssets)"
OutputPath="$(_WasmBuildImportMapHtmlPath)">
<Output TaskParameter="HtmlCandidates" ItemName="_HtmlCandidates" />
<Output TaskParameter="HtmlFilesToRemove" ItemName="_HtmlFilesToRemove" />
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
Copy link
Member

Choose a reason for hiding this comment

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

Is this friendly to incremental build ?

</WriteImportMapToHtml>

<!-- Replace modified HTML swa -->
<ItemGroup>
<_HtmlCandidatesNoMetadata
Include="@(_HtmlCandidates)"
RemoveMetadata="Integrity;Fingerprint" />
<_HtmlCandidatesNoMetadata ContentRoot="$(_WasmBuildImportMapHtmlPath)" />
</ItemGroup>
<DefineStaticWebAssets CandidateAssets="@(_HtmlCandidatesNoMetadata)">
<Output TaskParameter="Assets" ItemName="_UpdatedHtmlStaticWebAssets" />
</DefineStaticWebAssets>
<DefineStaticWebAssetEndpoints
CandidateAssets="@(_UpdatedHtmlStaticWebAssets)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="_UpdatedHtmlStaticWebAssetsEndpoint" />
</DefineStaticWebAssetEndpoints>
<ItemGroup>
<StaticWebAsset Remove="@(_HtmlFilesToRemove)" />
<StaticWebAsset Include="@(_UpdatedHtmlStaticWebAssets)" />
<StaticWebAssetEndpoint Include="@(_UpdatedHtmlStaticWebAssetsEndpoint)" />
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we remove the old endpoints too?

</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -737,5 +737,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="Microsoft.NET.Sdk.StaticWebAssets.Compression.targets" Condition="'$(CompressionEnabled)' == 'true'" />

<Import Project="Microsoft.NET.Sdk.StaticWebAssets.ServiceWorker.targets" Condition="'$(ServiceWorkerAssetsManifest)' != ''" />

<Import Project="Microsoft.NET.Sdk.StaticWebAssets.HtmlImportMap.targets" Condition="'$(WriteImportMapToHtml)' == 'true'" />

</Project>
Loading
Loading