Skip to content

Commit

Permalink
Update dotless and upgrade to netstandard
Browse files Browse the repository at this point in the history
  • Loading branch information
twenzel committed Apr 11, 2018
1 parent 793c6b7 commit 44bd296
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

This package compiles LESS files into CSS by hooking into the [LigerShark.WebOptimizer](https://github.com/ligershark/WebOptimizer) pipeline.

## Caution
Due to the lack of .NET Core/Standard support of the dotless package this extension for the [LigerShark.WebOptimizer](https://github.com/ligershark/WebOptimizer) pipeline is currently running on .NET Framework only.

## Install
Add the NuGet package [codeessentials.WebOptimizer.Dotless](https://nuget.org/packages/codeessentials.WebOptimizer.Dotless/) to any ASP.NET Core project supporting .NET Standard 2.0 or higher.

Expand All @@ -28,6 +25,7 @@ public void ConfigureServices(IServiceCollection services)
});
}
```

...and add `app.UseWebOptimizer()` to the `Configure` method anywhere before `app.UseStaticFiles`, like so:

```csharp
Expand Down
11 changes: 5 additions & 6 deletions src/PipelineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public static IEnumerable<IAsset> CompileLess(this IEnumerable<IAsset> assets)
/// <param name="sourceFiles">The path to the .less source files to compile.</param>
public static IAsset AddLessBundle(this IAssetPipeline pipeline, string route, params string[] sourceFiles)
{
return pipeline.AddBundle(route, "text/css; charset=UTF-8", sourceFiles)
return pipeline.AddBundle(route, "text/css; charset=UTF-8", sourceFiles).EnforceFileExtensions(".less")
.CompileLess()
.AdjustRelativePaths()
.Concatenate()
.FingerprintUrls()
.AddResponseHeader("X-Content-Type-Options", "nosniff")
.MinifyCss();
}

Expand All @@ -55,10 +56,7 @@ public static IAsset AddLessBundle(this IAssetPipeline pipeline, string route, p
/// <param name="pipeline">The asset pipeline.</param>
public static IEnumerable<IAsset> CompileLessFiles(this IAssetPipeline pipeline)
{
return pipeline.AddFiles("text/css; charset=UTF-8", "**/*.less")
.CompileLess()
.FingerprintUrls()
.MinifyCss();
return pipeline.CompileLessFiles("**/*.less");
}

/// <summary>
Expand All @@ -68,9 +66,10 @@ public static IEnumerable<IAsset> CompileLessFiles(this IAssetPipeline pipeline)
/// <param name="sourceFiles">A list of relative file names of the sources to compile.</param>
public static IEnumerable<IAsset> CompileLessFiles(this IAssetPipeline pipeline, params string[] sourceFiles)
{
return pipeline.AddFiles("text/css; charset=UFT-8", sourceFiles)
return pipeline.AddFiles("text/css; charset=UFT-8", sourceFiles).EnforceFileExtensions(".less")
.CompileLess()
.FingerprintUrls()
.AddResponseHeader("X-Content-Type-Options", "nosniff")
.MinifyCss();
}
}
Expand Down
31 changes: 15 additions & 16 deletions src/WebOptimizer.Dotless.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\WebOptimizer.Dotless.xml</DocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageTags>less, bundle, minify, optimize, asp.net core, dotless</PackageTags>
<Version>1.0.0-beta</Version>
<Authors>Toni Wenzel</Authors>
<Description>Compiles Less files for the LigerShark.WebOptimizer.Core system.</Description>
<Copyright>Copyright © Toni Wenzel</Copyright>
<PackageId>codeessentials.WebOptimizer.Dotless</PackageId>
<Product>codeessentials.WebOptimizer.Dotless</Product>
<PackageProjectUrl>https://github.com/twenzel/WebOptimizer.Dotless</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/twenzel/WebOptimizer.Dotless/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryUrl>https://github.com/twenzel/WebOptimizer.Dotless</RepositoryUrl>
<TargetFramework>netstandard2.0</TargetFramework>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\WebOptimizer.Dotless.xml</DocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageTags>less, bundle, minify, optimize, asp.net core, dotless</PackageTags>
<Version>1.0.0</Version>
<Authors>Toni Wenzel</Authors>
<Description>Compiles Less files for the LigerShark.WebOptimizer.Core system.</Description>
<Copyright>Copyright © Toni Wenzel</Copyright>
<PackageId>codeessentials.WebOptimizer.Dotless</PackageId>
<Product>codeessentials.WebOptimizer.Dotless</Product>
<PackageProjectUrl>https://github.com/twenzel/WebOptimizer.Dotless</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/twenzel/WebOptimizer.Dotless/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryUrl>https://github.com/twenzel/WebOptimizer.Dotless</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="dotless" Version="1.5.2" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="1.0.174-beta" />
<PackageReference Include="dotless.Core" Version="1.6.0.1" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="1.0.201" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions test/CompilerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class CompilerTest
public async Task Compile_Success()
{
var processor = new Compiler();
var pipeline = new Mock<IAssetPipeline>().SetupAllProperties();
var context = new Mock<IAssetContext>().SetupAllProperties();
var asset = new Mock<IAsset>().SetupAllProperties();
var env = new Mock<IHostingEnvironment>();
Expand Down Expand Up @@ -48,12 +47,10 @@ public async Task Compile_Success()
Assert.Equal("* {\n margin: 1px;\n}", result.AsString().Trim());
}


[Fact]
public async Task Compile_With_Imports_Success()
{
var processor = new Compiler();
var pipeline = new Mock<IAssetPipeline>().SetupAllProperties();
var context = new Mock<IAssetContext>().SetupAllProperties();
var asset = new Mock<IAsset>().SetupAllProperties();
var env = new Mock<IHostingEnvironment>();
Expand All @@ -66,7 +63,7 @@ public async Task Compile_With_Imports_Success()
var inputFile = new PhysicalFileInfo(new FileInfo(path));

context.Object.Content = new Dictionary<string, byte[]> {
{ "/file.less", "@import \"bar\"; @foo: 1px; * {margin: @foo}".AsByteArray() }
{ "/file.less", "@import \"bar\"; @foo: 1px; * {margin: @foo}".AsByteArray() }
};

context.Setup(s => s.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)))
Expand Down
12 changes: 5 additions & 7 deletions test/WebOptimizer.Dotless.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>

<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Moq" Version="4.7.145" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.8.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="1.0.174-beta" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="1.0.201" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 44bd296

Please sign in to comment.