Skip to content

Commit

Permalink
Merge pull request #48 from nhsuk/docs-assets
Browse files Browse the repository at this point in the history
Compile docs-only CSS in eleventy build
  • Loading branch information
davidhunter08 authored Apr 19, 2024
2 parents 98aef67 + 0c01248 commit 0054a7b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
23 changes: 15 additions & 8 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nunjucks from 'nunjucks'
import sass from 'sass'
import { EleventyHtmlBasePlugin } from '@11ty/eleventy'

const nunjucksEnv = nunjucks.configure([
Expand All @@ -16,16 +17,22 @@ export default function (eleventyConfig) {
// Configure a custom nunjucks environment
eleventyConfig.setLibrary('njk', nunjucksEnv)

// Copy static files
eleventyConfig.addPassthroughCopy({
'node_modules/nhsuk-frontend/dist/nhsuk.css': 'assets/nhsuk.css',
'dist/nhsapp.css': 'assets/nhsapp.css'
})

// Watch for changes in these directories and files
eleventyConfig.addWatchTarget('./docs/')
eleventyConfig.addWatchTarget('./src/')
eleventyConfig.addWatchTarget('./dist/nhsapp.css')

eleventyConfig.addTemplateFormats('scss')
eleventyConfig.addExtension('scss', {
outputFileExtension: 'css',
compile: async function (inputContent) {
let result = sass.compileString(inputContent, {
// Allow us to import scss files relative to the project root
loadPaths: ['.']
})
return async (data) => {
return result.css
}
}
})

// We need this HtmlBase plugin for serving our docs on github pages at a subdirectory
// https://www.11ty.dev/docs/plugins/html-base/
Expand Down
3 changes: 1 addition & 2 deletions docs/_includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">

<link href="/assets/nhsuk.css" rel="stylesheet" />
<link href="/assets/nhsapp.css" rel="stylesheet" />
<link href="/assets/css/app.css" rel="stylesheet" />

<title>{{ title }}</title>
</head>
Expand Down
10 changes: 10 additions & 0 deletions docs/assets/css/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Import all of the NHS.UK frontend core styles
@import "node_modules/nhsuk-frontend/packages/core/all.scss";

// Import specific components that we need from nhsuk-frontend
@import "node_modules/nhsuk-frontend/packages/components/skip-link/skip-link.scss";
@import "node_modules/nhsuk-frontend/packages/components/header/header.scss";
@import "node_modules/nhsuk-frontend/packages/components/hero/hero.scss";

// Import all styles from the NHS App frontend library
@import "src/all.scss";

0 comments on commit 0054a7b

Please sign in to comment.