Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AspNetCore.SassCompiler.Tasks/CompileSass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,16 @@ private void BindConfiguration(SassCompilerOptions options, IDictionary<string,
options.GenerateScopedCss = generateScopedCss;
if (configuration.TryGetValue("ScopedCssFolders", out value) && value is IList<object> scopedCssFolders)
options.ScopedCssFolders = scopedCssFolders.Where(x => x is string).Cast<string>().ToArray();
if (configuration.TryGetValue("IncludePaths", out value) && value is IList<object> includePaths)
options.IncludePaths = includePaths.OfType<string>().ToArray();
}

private IEnumerable<ITaskItem> GenerateSourceTarget(SassCompilerOptions options)
{
if (Directory.Exists(options.SourceFolder))
{
var arguments =
$"{Snapshot} {options.Arguments} {options.SourceFolder}:{options.TargetFolder} --update";
$"{Snapshot} {options.Arguments} {options.GetLoadPathArguments()} {options.SourceFolder}:{options.TargetFolder} --update";

var (success, output, error) = GenerateCss(arguments);

Expand Down Expand Up @@ -228,7 +230,7 @@ private IEnumerable<ITaskItem> GenerateScopedCss(SassCompilerOptions options)
if (directories.Count == 0)
yield break;

var arguments = $"{Snapshot} {options.Arguments} {string.Join(" ", directories)} --update";
var arguments = $"{Snapshot} {options.Arguments} {options.GetLoadPathArguments()} {string.Join(" ", directories)} --update";

var (success, output, error) = GenerateCss(arguments);

Expand Down
2 changes: 1 addition & 1 deletion AspNetCore.SassCompiler/AspNetCore.SassCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<PackageId>AspNetCore.SassCompiler</PackageId>
<Version>1.54.5</Version>
<Version>1.54.5.1</Version>
<Authors>koenvzeijl,sleeuwen,Michaelvs97</Authors>
<Description>Sass Compiler Library for .NET Core 3.1/5.x/6.x. without node</Description>
<PackageDescription>Sass Compiler Library for .NET Core 3.1/5.x/6.x. without node, using dart-sass as a compiler</PackageDescription>
Expand Down
2 changes: 1 addition & 1 deletion AspNetCore.SassCompiler/SassCompilerHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private Process GetSassProcess()

var process = new Process();
process.StartInfo.FileName = command.Filename;
process.StartInfo.Arguments = $"{command.Snapshot} --error-css --watch {_options.Arguments} {string.Join(" ", directories)}";
process.StartInfo.Arguments = $"{command.Snapshot} --error-css --watch {_options.Arguments} {_options.GetLoadPathArguments()} {string.Join(" ", directories)}";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
Expand Down
10 changes: 10 additions & 0 deletions AspNetCore.SassCompiler/SassCompilerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ public string TargetFolder
public bool GenerateScopedCss { get; set; } = true;

public string[] ScopedCssFolders { get; set; } = null;

public string[] IncludePaths { get; set; } = null;

public string GetLoadPathArguments()
{
if (IncludePaths == null || IncludePaths.Length == 0)
return "";

return $"--load-path {string.Join(" --load-path ", IncludePaths)}";
}
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You can also adjust the default configuration in the appsettings.json or sasscom
| Arguments | "--error-css" | Arguments passed to the dart-sass executable |
| GenerateScopedCss | true | Enable/disable support for scoped scss |
| ScopedCssFolders | ["Views", "Pages", "Shared", "Components"] | The folders in which .scss files are considered for scoped css |
| IncludePaths | [] | Add folders to search in when importing modules |

### Examples

Expand All @@ -41,6 +42,7 @@ You can also adjust the default configuration in the appsettings.json or sasscom
"Arguments": "--style=compressed",
"GenerateScopedCss": true,
"ScopedCssFolders": ["Views", "Pages", "Shared", "Components"],
"IncludePaths": [],

// You can override specific options based on the build configuration
"Configurations": {
Expand All @@ -63,6 +65,7 @@ You can also adjust the default configuration in the appsettings.json or sasscom
"Arguments": "--style=compressed",
"GenerateScopedCss": true,
"ScopedCssFolders": ["Views", "Pages", "Shared", "Components"],
"IncludePaths": [],

// You can override specific options based on the build configuration
"Configurations": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$header-color: red;
2 changes: 2 additions & 0 deletions Samples/AspNetCore.SassCompiler.Sample/Styles/site_sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
background-color: aliceblue;
}
}

@import 'subdir/file';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'variables'; // This should be taken from the Styles directory because of the load path

h1 {
color: $header-color;
}
7 changes: 4 additions & 3 deletions Samples/AspNetCore.SassCompiler.Sample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
// "SassCompiler": {
"AllowedHosts": "*",
"SassCompiler": {
// "SourceFolder": "Styles",
// "TargetFolder": "wwwroot\\css",
// "Arguments": "--error-css --no-source-map"
// }
"IncludePaths": ["Styles"]
}
}