Creating minification system.

pull/272/head
Halil İbrahim Kalkan 8 years ago
parent d05b83a3f5
commit 2118845a55

@ -180,6 +180,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Mvc.UI.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared", "src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj", "{86A3BB43-8FA2-4CC2-BAD0-A86C6C9D9585}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Mvc.UI.Tests", "test\Volo.Abp.AspNetCore.Mvc.UI.Tests\Volo.Abp.AspNetCore.Mvc.UI.Tests.csproj", "{7E0517E0-AE09-4E10-8469-308F065F2F43}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -502,6 +504,10 @@ Global
{86A3BB43-8FA2-4CC2-BAD0-A86C6C9D9585}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86A3BB43-8FA2-4CC2-BAD0-A86C6C9D9585}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86A3BB43-8FA2-4CC2-BAD0-A86C6C9D9585}.Release|Any CPU.Build.0 = Release|Any CPU
{7E0517E0-AE09-4E10-8469-308F065F2F43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E0517E0-AE09-4E10-8469-308F065F2F43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E0517E0-AE09-4E10-8469-308F065F2F43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E0517E0-AE09-4E10-8469-308F065F2F43}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -588,6 +594,7 @@ Global
{0AE814CE-E155-4259-8746-262D174AB510} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{2F5EE6D9-511B-4998-BD62-0B9F03E02432} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{86A3BB43-8FA2-4CC2-BAD0-A86C6C9D9585} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{7E0517E0-AE09-4E10-8469-308F065F2F43} = {447C8A77-E5F0-4538-8687-7383196D04EA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

@ -11,15 +11,15 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>ABP Web Application</title>
<!-- Add Material font (Roboto) and Material icon as needed -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<vc:abp-style-bundle name="GlobalStyles"></vc:abp-style-bundle>
<link rel="stylesheet" type="text/css" href="~/views/shared/_AppLayout.css"/>
<link rel="stylesheet" type="text/css" href="~/views/shared/_AppLayout.css" />
@RenderSection("styles", false)
</head>
<body>
@ -32,7 +32,10 @@
</div>
<vc:abp-script-bundle name="GlobalScripts"></vc:abp-script-bundle>
<script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script>
<script type="text/javascript" src="~/Abp/ServiceProxyScript"></script>
@RenderSection("scripts", false)
</body>

@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
@ -44,10 +44,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared
"/libs/abp/jquery/abp.resource-loader.js",
"/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js",
"/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/abp.modal-manager.js",
"/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables-extensions.js",
"/Abp/ApplicationConfigurationScript",
"/Abp/ServiceProxyScript"
"/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables-extensions.js"
});
});

@ -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);
}
}
}

@ -3,7 +3,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Mvc
namespace Volo.Abp.AspNetCore.Mvc.UI
{
[DependsOn(typeof(AbpAspNetCoreMvcModule))]
[DependsOn(typeof(AbpUiNavigationModule))]

@ -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
);
}
}
}
}

@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpScriptBundle
{

@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpStyleBundle
{

@ -14,6 +14,10 @@
<EmbeddedResource Include="Views\**\*.cshtml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUglify" Version="1.5.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" />
<ProjectReference Include="..\Volo.Abp.UI.Navigation\Volo.Abp.UI.Navigation.csproj" />

@ -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 @@
(function() {
//lib1-js-content
})();

@ -0,0 +1,3 @@
.lib2-css-content {
color: blue;
}

@ -0,0 +1,3 @@
(function() {
//lib2-js-content
})();
Loading…
Cancel
Save