-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
maraf
wants to merge
20
commits into
dotnet:main
Choose a base branch
from
maraf:maraf/HtmlImportMap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e882406
Copy code from prototype
maraf ef4843e
Don't generate the manifest to temp file, compute it on the fly
maraf 3550dc0
Build logic
maraf fcf527f
Remove CSS fingerprinting
maraf a4582e2
Remove wasm from msbuild property name
maraf ca1578d
Remove JS fingerprinting
maraf ea7f7fd
Use empty script type=importmap as a placeholder
maraf 1d8d137
Operate directly on endpoints
maraf fab6429
Operate directly on endpoints
maraf 9709397
Use fingerprint pattern
maraf 45bf5d7
Publish integration
maraf b212724
Fix getting publish HTML files
maraf 79e5fb7
Publish test
maraf ebd6e55
Build test
maraf c31496e
Enable dotnet.js fingerprinting when targeting .NET 10 or newer
maraf 25a271f
Refactor targets based on JSModule pattern
maraf 961c36e
Swap order of dependencies
maraf f0d4ea4
Revert changes to GenerateStaticWebAssetEndpointsManifest
maraf 1221414
Merge branch 'main' into maraf/HtmlImportMap
maraf b5ee5a5
Don't set WasmFingerprintDotnetJs for .NET 10+
maraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.HtmlImportMap.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
</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" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we remove the old endpoints too? |
||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?