Skip to content

Commit

Permalink
Merge pull request #2010 from sbwalker/dev
Browse files Browse the repository at this point in the history
Add support for ES6 module JavaScript resources
  • Loading branch information
sbwalker committed Feb 19, 2022
2 parents a2417bb + b68e3cb commit e305c48
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Oqtane.Client/Modules/ModuleBase.cs
Expand Up @@ -55,7 +55,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
var scripts = new List<object>();
foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script && item.Declaration != ResourceDeclaration.Global))
{
scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "" });
scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", ismodule = resource.IsModule ?? false});
}
if (scripts.Any())
{
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Client/Themes/ThemeBase.cs
Expand Up @@ -34,7 +34,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
var scripts = new List<object>();
foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script && item.Declaration != ResourceDeclaration.Global))
{
scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "" });
scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", ismodule = resource.IsModule ?? false });
}
if (scripts.Any())
{
Expand Down
3 changes: 3 additions & 0 deletions Oqtane.Server/wwwroot/js/interop.js
Expand Up @@ -232,6 +232,9 @@ Oqtane.Interop = {
if (path === scripts[s].href && scripts[s].crossorigin !== '') {
element.crossOrigin = scripts[s].crossorigin;
}
if (path === scripts[s].href && scripts[s].ismodule === true) {
element.type = "module";
}
}
}
})
Expand Down
8 changes: 6 additions & 2 deletions Oqtane.Shared/Models/Resource.cs
Expand Up @@ -33,14 +33,18 @@ public class Resource
public string Bundle { get; set; }

/// <summary>
/// Determines if the Resource is global, meaning that the entire solution uses it or just some modules.
/// TODO: VERIFY that this explanation is correct.
/// Determines if the Resource is global or local, meaning that the entire solution uses it or just some modules.
/// </summary>
public ResourceDeclaration Declaration { get; set; }

/// <summary>
/// If the Resource should be included in the `head` of the HTML document or the `body`
/// </summary>
public ResourceLocation Location { get; set; }

/// <summary>
/// For Scripts this allows type="module" registrations - not applicable to Stylesheets
/// </summary>
public bool? IsModule { get; set; }
}
}

0 comments on commit e305c48

Please sign in to comment.