mirror of https://github.com/abpframework/abp.git
26 changed files with 307 additions and 42 deletions
@ -1,26 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Bundling |
|||
{ |
|||
public class BundleManager : IBundleManager, ITransientDependency |
|||
{ |
|||
private readonly BundlingOptions _options; |
|||
|
|||
public BundleManager(IOptions<BundlingOptions> options) |
|||
{ |
|||
_options = options.Value; |
|||
} |
|||
|
|||
public List<string> GetStyleBundleFiles(string bundleName) |
|||
{ |
|||
return _options.StyleBundles.GetFiles(bundleName); |
|||
} |
|||
|
|||
public List<string> GetScriptBundleFiles(string bundleName) |
|||
{ |
|||
return _options.ScriptBundles.GetFiles(bundleName); |
|||
} |
|||
} |
|||
} |
|||
@ -1,6 +1,6 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Bundling |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class BundleCollection |
|||
{ |
|||
@ -0,0 +1,52 @@ |
|||
using System.Collections.Concurrent; |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class BundleManager : IBundleManager, ISingletonDependency |
|||
{ |
|||
private readonly BundlingOptions _options; |
|||
private readonly IHostingEnvironment _hostingEnvironment; |
|||
private readonly IBundler _bundler; |
|||
|
|||
private readonly ConcurrentDictionary<string, string> _cache; |
|||
|
|||
public BundleManager( |
|||
IOptions<BundlingOptions> options, |
|||
IHostingEnvironment hostingEnvironment, |
|||
IBundler bundler) |
|||
{ |
|||
_hostingEnvironment = hostingEnvironment; |
|||
_bundler = bundler; |
|||
_options = options.Value; |
|||
|
|||
_cache = new ConcurrentDictionary<string, string>(); |
|||
} |
|||
|
|||
public List<string> GetStyleBundleFiles(string bundleName) |
|||
{ |
|||
return _options.StyleBundles.GetFiles(bundleName); |
|||
} |
|||
|
|||
public List<string> GetScriptBundleFiles(string bundleName) |
|||
{ |
|||
//if (_hostingEnvironment.IsDevelopment())
|
|||
{ |
|||
return _options.ScriptBundles.GetFiles(bundleName); |
|||
} |
|||
|
|||
return new List<string> |
|||
{ |
|||
_cache.GetOrAdd( |
|||
"SCRIPT:" + bundleName, |
|||
() => _bundler.CreateBundle( |
|||
_options.ScriptBundles.GetFiles(bundleName) |
|||
) |
|||
) |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class Bundler : IBundler, ITransientDependency |
|||
{ |
|||
public Bundler() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public string CreateBundle(List<string> files) |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.Bundling |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class BundlingOptions |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Bundling |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public interface IBundleManager |
|||
{ |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public interface IBundler |
|||
{ |
|||
string CreateBundle(List<string> files); |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Minification |
|||
{ |
|||
public interface IJavascriptMinifier |
|||
{ |
|||
string Minify(string source, string fileName = null); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System.Collections.Generic; |
|||
using System.Runtime.Serialization; |
|||
using NUglify; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Minification.NUglify |
|||
{ |
|||
public class NUglifyException : AbpException |
|||
{ |
|||
public List<UglifyError> Errors { get; set; } |
|||
|
|||
public NUglifyException(string message, List<UglifyError> errors) |
|||
: base(message) |
|||
{ |
|||
Errors = errors; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Constructor for serializing.
|
|||
/// </summary>
|
|||
public NUglifyException(SerializationInfo serializationInfo, StreamingContext context) |
|||
: base(serializationInfo, context) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using NUglify; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Minification.NUglify |
|||
{ |
|||
public class NUglifyJavascriptMinifier : IJavascriptMinifier, ITransientDependency |
|||
{ |
|||
public string Minify(string source, string fileName = null) |
|||
{ |
|||
var result = Uglify.Js(source, fileName); |
|||
CheckErrors(result); |
|||
return result.Code; |
|||
} |
|||
|
|||
private static void CheckErrors(UglifyResult result) |
|||
{ |
|||
if (result.HasErrors) |
|||
{ |
|||
throw new NUglifyException( |
|||
"There are some errors on uglifying the given source code!", |
|||
result.Errors |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.0</TargetFramework> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<AssemblyName>Volo.Abp.AspNetCore.Mvc.UI.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.AspNetCore.Mvc.UI.Tests</PackageId> |
|||
<PreserveCompilationContext>true</PreserveCompilationContext> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" /> |
|||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.Mvc.UI\Volo.Abp.AspNetCore.Mvc.UI.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.AspNetCore.Tests\Volo.Abp.AspNetCore.Tests.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<!-- Below ItemGroup and Target tags are added according to https://github.com/aspnet/Hosting/issues/959#issuecomment-286351703 --> |
|||
|
|||
<!-- Solves Problem#2 (404 when executing service calls hosted in other assemblies) --> |
|||
<!-- https://github.com/Microsoft/vstest/issues/196.--> |
|||
<ItemGroup> |
|||
<None Update="xunit.runner.json"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
<!-- https://github.com/NuGet/Home/issues/4412. --> |
|||
<Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''"> |
|||
<ItemGroup> |
|||
<DepsFilePaths Include="$([System.IO.Path]::ChangeExtension('%(_ResolvedProjectReferencePaths.FullPath)', '.deps.json'))" /> |
|||
</ItemGroup> |
|||
|
|||
<Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutputPath)" Condition="Exists('%(DepsFilePaths.FullPath)')" /> |
|||
</Target> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.AspNetCore.TestBase; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI |
|||
{ |
|||
public abstract class AbpAspNetCoreMvcUiTestBase : AbpAspNetCoreIntegratedTestBase<Startup> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.AspNetCore.TestBase; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreTestBaseModule), |
|||
typeof(AbpAspNetCoreMvcUiModule), |
|||
typeof(AbpAutofacModule) |
|||
)] |
|||
public class AbpAspNetCoreMvcUiTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpAspNetCoreMvcUiTestModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Minification.NUglify |
|||
{ |
|||
public class NUglifyJavascriptMinifier_Tests : AbpAspNetCoreMvcUiTestBase |
|||
{ |
|||
private readonly NUglifyJavascriptMinifier _nUglifyJavascriptMinifier; |
|||
|
|||
public NUglifyJavascriptMinifier_Tests() |
|||
{ |
|||
_nUglifyJavascriptMinifier = GetRequiredService<NUglifyJavascriptMinifier>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Minify_Simple_Code() |
|||
{ |
|||
const string source = "var x = 5; var y = 6;"; |
|||
|
|||
var minified = _nUglifyJavascriptMinifier.Minify(source); |
|||
|
|||
minified.Length.ShouldBeGreaterThan(0); |
|||
minified.Length.ShouldBeLessThan(source.Length); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System; |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public IServiceProvider ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpAspNetCoreMvcUiTestModule>(options => |
|||
{ |
|||
options.UseAutofac(); |
|||
}); |
|||
|
|||
//TODO: This is needed because ASP.NET Core does not use IServiceProviderFactory!
|
|||
return services.BuildServiceProviderFromFactory(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
.lib1-css-content { |
|||
color: red; |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
(function() { |
|||
//lib1-js-content
|
|||
})(); |
|||
@ -0,0 +1,3 @@ |
|||
.lib2-css-content { |
|||
color: blue; |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
(function() { |
|||
//lib2-js-content
|
|||
})(); |
|||
Loading…
Reference in new issue