Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to modern Sass api #595

Merged
merged 4 commits into from
Jan 13, 2025
Merged

Switch to modern Sass api #595

merged 4 commits into from
Jan 13, 2025

Conversation

DavidBiddle
Copy link
Contributor

@DavidBiddle DavidBiddle commented Jan 10, 2025

What problem does this pull request solve?

Trello card: https://trello.com/c/pfzCTVnB/2066-investigate-asset-building-issue-with-modern-sass-api

We were seeing an issue with assets failing to build properly using the 'modern' Sass API. After investigating this appears to be caused by a bug in the Vite internal sass importer (vitejs/vite#19196).

This PR:

  • uses the sass NodePackageImporter import govuk-frontend, which bypasses that bug and also offers us some other advantages (see commit message for more details)
  • updates to use the modern API
  • removes some redundant imports
  • uses a more compact API for setting the asset paths

Things to consider when reviewing

  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

@DavidBiddle DavidBiddle marked this pull request as ready for review January 13, 2025 13:33
We were previously using the 'legacy' Sass API, which is deprecated.

This commit switches to the modern version

This will cause some assets not to build properly - this is [a known issue](https://trello.com/c/pfzCTVnB/2066-investigate-asset-building-issue-with-modern-sass-api)
which we'll solve in an upcoming commit.
There's a bug in the way Vite's inbuilt sass importing works that means
some of our assets don't build properly if we import the govuk-frontend
styles using the @GOVUK alias.

We can get around this by using Sass's builtin NodEpackageImporter to
import the govuk-frontend styles. This bypasses the Vite import code
that causes the issue.

It's also better for a couple of other reasons. It makes it clear that
this import is coming from an npm package (which was obscured slightly
when we were using the alias). It also makes us resilient to structure
changes in the govuk-frontend package (NodePackageImporter uses the
'sass' field in govuk-frontend's package.json to determine the file to
import, so we no longer need to point to a specific file which could
change).
These files were being imported twice unnecessarily - this commit
removes the duplicates.
We were configuring both $govuk-fonts-path and $govuk-images-path. This
was overly verbose, since for our folder structure we can configure
$govuk-assets-path and it will generate values for $govuk-fonts-path and
$govuk-images-path identical to those we were passing in.
@DavidBiddle DavidBiddle force-pushed the switch-to-modern-sass-api branch from 7c54090 to 319986d Compare January 13, 2025 13:33
@DavidBiddle DavidBiddle changed the title Switch to modern sass api Switch to modern Sass api Jan 13, 2025
Copy link
Contributor

@thomasiles thomasiles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice and well documented 🏅

works for me locally.

@DavidBiddle DavidBiddle merged commit 8b70ac8 into main Jan 13, 2025
4 checks passed
@DavidBiddle DavidBiddle deleted the switch-to-modern-sass-api branch January 13, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants