|
| 1 | +# Sample with SASS integration |
| 2 | + |
| 3 | +This sample demonstrates how to set up a project with SASS that can reference the `govuk-frontend` scss source files. |
| 4 | + |
| 5 | +To replicate this setup in your own project, follow these steps: |
| 6 | + |
| 7 | +1. Install the `GovUk.Frontend.AspNetCore` package: |
| 8 | + ```shell |
| 9 | + dotnet add package GovUk.Frontend.AspNetCore |
| 10 | + ``` |
| 11 | + |
| 12 | +2. Add services to your application: |
| 13 | + ```cs |
| 14 | + builder.Services.AddGovUkFrontend(); |
| 15 | + ``` |
| 16 | + |
| 17 | +3. Enable `govuk-frontend` package restore on build by adding the following to your `.csproj` file: |
| 18 | + ```xml |
| 19 | + <PropertyGroup> |
| 20 | + <RestoreGovUkFrontendNpmPackage>true</RestoreGovUkFrontendNpmPackage> |
| 21 | + </PropertyGroup> |
| 22 | + ``` |
| 23 | +This will copy the contents of the `govuk-frontend` NPM package into your project. |
| 24 | + |
| 25 | +> [!WARNING] |
| 26 | +> When you enable `RestoreGovUkFrontendNpmPackage`, the automatic hosting of `govuk-frontend` files is disabled. |
| 27 | +> By default, the static assets will be copied to `wwwroot/assets`. |
| 28 | +> You must ensure that the required CSS and JavaScript is available. |
| 29 | +
|
| 30 | +> [!NOTE] |
| 31 | +> Add `wwwroot/assets` and `govuk-frontend` to your `.gitignore` file to avoid committing the copied files to your repository. |
| 32 | +
|
| 33 | +4. Install the `DartSassBuilder` package: |
| 34 | + ```shell |
| 35 | + dotnet add package DartSassBuilder |
| 36 | + ``` |
| 37 | + |
| 38 | +5. Configure SASS compilation by adding the following to your `.csproj` file: |
| 39 | + ```xml |
| 40 | + <PropertyGroup> |
| 41 | + <EnableDefaultSassItems>false</EnableDefaultSassItems> |
| 42 | + </PropertyGroup> |
| 43 | + |
| 44 | + <ItemGroup> |
| 45 | + <SassFile Include="wwwroot/*.scss" Exclude="govuk-frontend/**/*.css" /> |
| 46 | + </ItemGroup> |
| 47 | + ``` |
| 48 | + |
| 49 | +6. Create your SASS files in the `wwwroot` directory. From there you can import the govuk-frontend styles. For example, create a file named `main.scss` in the `wwwroot` directory with the following content: |
| 50 | + ```scss |
| 51 | + @import "govuk-frontend/govuk/all"; |
| 52 | + |
| 53 | + /* your custom styles here */ |
| 54 | + ``` |
0 commit comments