Browse Source

Handle changes in razor bundles on development time.

pull/395/head
Halil ibrahim Kalkan 8 years ago
parent
commit
242875a3b8
  1. 44
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs
  2. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs
  3. 13
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs
  4. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs
  5. 14
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/Index.cshtml
  6. 7
      modules/identity/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj

44
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs

@ -24,7 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
/// <param name="configureAction">Initial configuration action.</param>
/// <returns>Returns this object for chained calls.</returns>
public BundleConfigurationCollection Add(
[NotNull] string bundleName,
[NotNull] string bundleName,
[CanBeNull] Action<BundleConfiguration> configureAction = null)
{
if (!TryAdd(bundleName, configureAction))
@ -42,43 +42,55 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
/// </summary>
/// <param name="bundleName">Bundle name.</param>
/// <param name="configureAction">Initial configuration action.</param>
/// <param name="overrideIfExists">
/// Overrides the bundle even if it does exists.
/// This option is designed to be used only for development time
/// where bundle configuration action may change.
/// </param>
/// <returns>Returns true if added. Returns false if it's already added before.</returns>
public bool TryAdd(
[NotNull] string bundleName,
[CanBeNull] Action<BundleConfiguration> configureAction = null)
[NotNull] string bundleName,
[CanBeNull] Action<BundleConfiguration> configureAction = null,
bool overrideIfExists = false)
{
Check.NotNull(bundleName, nameof(bundleName));
if (_bundles.ContainsKey(bundleName))
if (overrideIfExists)
{
return false;
_bundles[bundleName] = CreateBundle(bundleName, configureAction);
return true;
}
var bundle = new BundleConfiguration(bundleName);
configureAction?.Invoke(bundle);
if (_lazyBundleConfigurationActions.TryGetValue(bundleName, out var configurationActions))
if (_bundles.ContainsKey(bundleName))
{
lock (configurationActions)
{
configurationActions.ForEach(c => c.Invoke(bundle));
}
return false;
}
var bundle = CreateBundle(bundleName, configureAction);
if (!_bundles.TryAdd(bundleName, bundle))
{
return false;
}
if (configurationActions != null)
return true;
}
private BundleConfiguration CreateBundle(string bundleName, Action<BundleConfiguration> configureAction)
{
var bundle = new BundleConfiguration(bundleName);
configureAction?.Invoke(bundle);
if (_lazyBundleConfigurationActions.TryGetValue(bundleName, out var configurationActions))
{
lock (configurationActions)
{
configurationActions.Clear();
configurationActions.ForEach(c => c.Invoke(bundle));
}
}
return true;
return bundle;
}
/// <summary>

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
@ -18,15 +19,18 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
protected IBundleManager BundleManager { get; }
protected IHybridWebRootFileProvider WebRootFileProvider { get; }
protected IHostingEnvironment HostingEnvironment { get; }
protected readonly BundlingOptions Options;
protected AbpTagHelperResourceService(
IBundleManager bundleManager,
IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options)
IOptions<BundlingOptions> options,
IHostingEnvironment hostingEnvironment)
{
BundleManager = bundleManager;
WebRootFileProvider = webRootFileProvider;
HostingEnvironment = hostingEnvironment;
Options = options.Value;
Logger = NullLogger<AbpTagHelperResourceService>.Instance;

13
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem;
@ -11,19 +13,22 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
public AbpTagHelperScriptService(
IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options
IOptions<BundlingOptions> options,
IHostingEnvironment hostingEnvironment
) : base(
bundleManager,
webRootFileProvider,
options)
options,
hostingEnvironment)
{
}
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
{
Options.StyleBundles.TryAdd(
Options.ScriptBundles.TryAdd(
bundleName,
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration))
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)),
HostingEnvironment.IsDevelopment() && bundleItems.Any()
);
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem;
@ -11,11 +13,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
public AbpTagHelperStyleService(
IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options
IOptions<BundlingOptions> options,
IHostingEnvironment hostingEnvironment
) : base(
bundleManager,
webRootFileProvider,
options)
options,
hostingEnvironment)
{
}
@ -23,7 +27,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{
Options.StyleBundles.TryAdd(
bundleName,
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration))
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)),
HostingEnvironment.IsDevelopment() && bundleItems.Any()
);
}

14
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/Index.cshtml

@ -17,18 +17,18 @@
<h2>@L["Roles"]</h2>
</abp-column>
<abp-column size-md="_6" class="text-right">
<abp-button button-type="Primary" name="CreateRole" text="@L["NewRole"].Value" icon="plus"/>
<abp-button button-type="Primary" name="CreateRole" text="@L["NewRole"].Value" icon="plus" />
</abp-column>
</abp-row>
</abp-card-header>
<abp-card-body>
<abp-table striped-rows="true" class="nowrap">
<thead>
<tr>
<th>@L["Actions"]</th>
<th>@L["RoleName"]</th>
</tr>
</thead>
<thead>
<tr>
<th>@L["Actions"]</th>
<th>@L["RoleName"]</th>
</tr>
</thead>
</abp-table>
</abp-card-body>
</abp-card>

7
modules/identity/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj

@ -15,18 +15,17 @@
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Pages\**\*.cshtml" Exclude="*.cs" />
<EmbeddedResource Include="Pages\**\*.*" Exclude="*.cs" />
<EmbeddedResource Include="Localization\Resources\**\*.json" />
</ItemGroup>
<ItemGroup>
<Content Remove="Pages\**\*.cshtml" />
<Content Remove="Pages\**\*.*" />
<Content Include="Pages\**\*.cs" />
<Content Remove="Localization\Resources\**\*.json" />
<Content Remove="compilerconfig.json" />
<Content Remove="compilerconfig.json.defaults" />
<Content Remove="Properties\launchSettings.json" />
<EmbeddedResource Include="Pages\Identity\Roles\index.js" />
<EmbeddedResource Include="Pages\Identity\Users\index.js" />
<None Include="compilerconfig.json" />
<None Include="Properties\launchSettings.json" />
</ItemGroup>

Loading…
Cancel
Save