[ASP.NET] Add support for JS modules and initializers#19270
Conversation
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
32cc7b6 to
c910ea9
Compare
c910ea9 to
b76f82f
Compare
e06a57a to
2112387
Compare
2112387 to
714dd8c
Compare
|
This PR is broken down into three commits:
|
d3159fe to
2c8f963
Compare
4886a7d to
2f01e2f
Compare
| <GetFileHash Files="@(_BlazorJsModuleCandidatesForBuildWithTargetPath)" Algorithm="SHA256" HashEncoding="base64"> | ||
| <Output TaskParameter="Items" ItemName="_BlazorOutputWithHash" /> | ||
| </GetFileHash> | ||
|
|
|
|
||
| <Target Name="_ProcessPublishFilesForBlazor" DependsOnTargets="LoadStaticWebAssetsBuildManifest" AfterTargets="ILLink"> | ||
| <Target Name="ProcessPublishFilesForBlazor" DependsOnTargets="LoadStaticWebAssetsBuildManifest" AfterTargets="ILLink"> |
There was a problem hiding this comment.
Is this meant to be a user extensibility point? Is there a reason they cannot configure itemgroups that are consumed by this globally (outside of a target)? We've had a terrible record of telling people to hook up to targets and taking it away when we refactor or change our implementation.
There was a problem hiding this comment.
We need to compute the list of Blazor assets, which happens in this target, and then we pick up any potential result from modifying it, and we add it to the list of assets.
I went this route becasue I believe its the simplest for customers, do you have any other way in mind that keeps the simplicity and gives us more flexibility?
The other thing I can think of is to get them to add themselves to a property group, and we'll make sure they are always called at the right time, how does that sound?
2c8f963 to
ddaddf4
Compare
e0da787 to
720d8d2
Compare
190fc7f to
1dd270d
Compare
ca1940c to
cbcd250
Compare
cbcd250 to
c11ed33
Compare
c11ed33 to
12cc134
Compare
|
@StevenRasmussen they only get copied at publish time. You can edit them in place and they will be served from there. |
|
Thanks for such a quick reply! So just to clarify: while debugging I shouldn't see them placed in the var module = await JS.InvokeAsync<IJSObjectReference>("import", "./Overlay.razor.js"); |
|
Ok. Sorry about the posts but I think this is resolved. I guess you need to specify a different path when using a Razor Class Library. Using the following seemed to work: _module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/RazorClassLibrary/Overlay.razor.js");If I have any further questions I'll open up a new ticket. Thanks! |



This PR adds support for JS Modules and initializers:
dotnet/aspnetcore#26145
dotnet/aspnetcore#32353
JS modules are discovered based on the following patterns:
We discover these files and copy them to the output folder in the right location (we strip the pages, shared, views, components, prefix)
Blazor applications can load these modules in the same way they load other modules, the only addition is that we define this convention instead of you having to do it manually.
For JS initializers:
$(PackageId).lib.module.jswhich will be detected as a library initializer.MVC/Razor pages applications won't automatically load any of the library initializers, however, it is trivial to include a small script to fetch the manifest and trigger the load of all the library initializers.
Finally, this PR includes a small set of changes to the Blazor publish process to enable customizing the blazor build process. We do this by collecting the list of Blazor files and writing a file to disk containing their full paths. That new file is included in the blazor.boot.json manifest in a new
extensionssection that contains a dictionary of custom extensions by name.This is enough to prove that users can customize the Blazor build process inside their app or from an external nuget package to suit your requirements. Upon boot (outside of the scope of this PR), blazor will load the blazor.boot.json manifest, load the library initializers and invoke them giving them their options, from which they can customize the remaining loading process.
This PR has been updated based on our discussions