Skip to content

Instantly share code, notes, and snippets.

@askeijaz
Created July 13, 2025 17:11
Show Gist options
  • Select an option

  • Save askeijaz/2049d3862764ce379e3754f193516d33 to your computer and use it in GitHub Desktop.

Select an option

Save askeijaz/2049d3862764ce379e3754f193516d33 to your computer and use it in GitHub Desktop.
Guide to configuring Hugo with Dart Sass and SCSS modules

πŸ’‘ Using Dart Sass in Hugo (Extended Version) with SCSS Modules

This guide walks through how to fully switch to Dart Sass for styling in a Hugo static site. This removes all dependency on deprecated LibSass and uses the recommended Dart Sass SCSS module system (@use, @forward).

βœ… Prerequisites

  • Hugo Extended version (brew install hugo)
  • Dart Sass installed (brew install sass/sass/sass)
  • A proper SCSS folder structure under /assets/scss/

πŸ—‚οΈ Project Structure

assets/
└── scss/
    β”œβ”€β”€ base/
    β”‚   β”œβ”€β”€ _variables.scss
    β”‚   β”œβ”€β”€ _typography.scss
    β”‚   β”œβ”€β”€ _reset.scss
    β”‚   └── _utilities.scss
    β”œβ”€β”€ components/
    β”‚   β”œβ”€β”€ _navbar.scss
    β”‚   β”œβ”€β”€ _footer.scss
    β”‚   β”œβ”€β”€ _cards.scss
    β”‚   └── _hero.scss
    β”œβ”€β”€ layout/
    β”‚   └── _grid.scss
    β”œβ”€β”€ themes/
    β”‚   β”œβ”€β”€ _darkmode.scss
    β”‚   └── _maverick.scss
    └── styles.scss

πŸ“„ styles.scss (Entry Point)

@use "scss/base/variables" as *;
@use "scss/base/reset";
@use "scss/base/typography";
@use "scss/base/utilities";
@use "scss/layout/grid";
@use "scss/components/navbar";
@use "scss/components/footer";
@use "scss/components/cards";
@use "scss/components/hero";
@use "scss/themes/darkmode";
@use "scss/themes/maverick";

🧠 Using Dart Sass in Hugo (layouts/partials/head.html)

{{ $options := dict "transpiler" "dartsass" "targetPath" "css/main.css" "outputStyle" "compressed" }}
{{ $styles := resources.Get "scss/styles.scss" | toCSS $options | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Integrity }}">

πŸ’‘ This inline option forces Hugo to use Dart Sass even if LibSass is still linked internally.


❌ Remove Old Config (if present)

In config.toml or hugo.toml:

# REMOVE THIS:
#[markup.sass]
#  useDartSass = true

# OPTIONAL (not necessary if using inline dict):
[params.sass]
  transpiler = "dartsass"

βœ… Verify Hugo Uses Dart Sass

hugo env

You should see:

github.com/sass/dart-sass/compiler="1.89.2"
...

πŸ§ͺ Run Hugo Server

hugo server --cleanDestinationDir --ignoreCache

You should now see your styles applied correctly using Dart Sass features like @use, @forward, @mixin, and SCSS scoping.


πŸ™Œ Credits

Originally built by @askeijaz using Pygments, Dart Sass, and Hugo’s resources pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment