-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: review and update production guidance
- Loading branch information
1 parent
888509e
commit eb17538
Showing
8 changed files
with
367 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
layout: layouts/get-started.njk | ||
subsection: Setup for production | ||
title: Import MoJ Frontend CSS | ||
eleventyNavigation: | ||
key: Import CSS | ||
parent: Setup for production | ||
order: 50 | ||
excerpt: "To load the CSS from MoJ Frontend, you can either add MoJ Frontend and GOV.UK Frontend’s CSS files to your HTML or load the CSS into your own Sass file." | ||
--- | ||
|
||
To use the CSS from MoJ Frontend and GOV.UK Frontend, you can either: | ||
|
||
- add MoJ Frontend and GOV.UK Frontend’s CSS files to your HTML | ||
- load the CSS files into your own Sass file | ||
|
||
## Add the CSS file to your HTML | ||
|
||
If you decide to add the CSS to your HTML, you can do one of the following: | ||
|
||
- serve the CSS files from the combined stylesheets folders – recommended | ||
- copy the CSS files into your application | ||
|
||
## Serve the CSS files from the combined stylesheets folders – recommended | ||
|
||
Set up your routing so requests for the CSS files in `<YOUR-SITE-URL>/stylesheets` are served from both `/node_modules/govuk-frontend/dist/govuk` and `/node_modules/@ministryofjustice/frontend/moj`. | ||
|
||
For example if you’re using [express.js](https://expressjs.com/), add the following to your `app.js` file: | ||
|
||
```js | ||
router.use('/stylesheets', [ | ||
express.static('node_modules/@ministryofjustice/frontend/moj'), | ||
express.static('node_modules/govuk-frontend/dist/govuk') | ||
]) | ||
``` | ||
|
||
Then link the CSS files inside the `<head>` tag of your HTML page or page template. | ||
|
||
```html | ||
<head> | ||
<!-- // ... --> | ||
<link rel="stylesheet" href="/stylesheets/govuk-frontend.min.css"> | ||
<link rel="stylesheet" href="/stylesheets/moj-frontend.min.css"> | ||
<!-- // ... --> | ||
</head> | ||
``` | ||
|
||
## Copy the CSS files into your application | ||
|
||
If you decide to copy the CSS files instead, copy both `/node_modules/@ministryofjustice/frontend/moj/moj-frontend.min.css` and `/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css` into `<YOUR-APP>/stylesheets` and link the CSS files using the example above. | ||
|
||
You should use an automated task or your build pipeline to copy the files, so your project folder stays up to date when updates to MoJ Frontend and GOV.UK Frontend are released. | ||
|
||
## Load using Sass | ||
|
||
To load all the Sass rules from both MoJ Frontend and GOV.UK Frontend, add the following to your Sass file: | ||
|
||
```scss | ||
@forward "node_modules/govuk-frontend/dist/govuk"; | ||
@forward "node_modules/@ministryofjustice/frontend/moj/all"; | ||
``` | ||
|
||
## Load an individual component’s CSS using a single Sass forward | ||
|
||
You can also load a component and all its dependencies without loading `node_modules/@ministryofjustice/frontend/moj/all` first. | ||
|
||
To load the button menu component for example, add the following to your Sass file: | ||
|
||
```scss | ||
@forward "node_modules/@ministryofjustice/frontend/moj/components/button-menu/button-menu"; | ||
``` | ||
|
||
## Simplify Sass load paths | ||
|
||
If you want to make Sass load paths shorter, add both `node_modules/@ministryofjustice/frontend` and `node_modules/govuk-frontend/dist` to either your: | ||
|
||
- [Sass load paths](https://sass-lang.com/documentation/at-rules/import#finding-the-file) | ||
- [assets paths](http://guides.rubyonrails.org/asset_pipeline.html#search-paths) if you use Ruby in your project | ||
|
||
For example, using the Sass compiler: | ||
|
||
```js | ||
compile('src/stylesheets/application.scss', { | ||
loadPaths: [ | ||
'node_modules/@ministryofjustice/frontend', | ||
'node_modules/govuk-frontend/dist', | ||
], | ||
quietDeps: true | ||
}) | ||
``` | ||
|
||
You can then load stylesheets without using `node_modules/@ministryofjustice/frontend` and `node_modules/govuk-frontend/dist` in your paths: | ||
|
||
```scss | ||
@forward "govuk"; | ||
@forward "moj/all"; | ||
``` | ||
|
||
## Override with your own CSS | ||
|
||
If you want to override MoJ Frontend’s styles with your own styles, `@forward` MoJ Frontend’s styles before your own Sass rules. | ||
|
||
## Silence deprecation warnings from dependencies in Dart Sass | ||
|
||
You may see deprecation warnings when compiling your Sass. For example: | ||
|
||
```console | ||
DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0. | ||
``` | ||
|
||
We’re currently unable to fix deprecation warnings from MoJ Frontend. However, you can silence the warnings by following the [Silence deprecation warnings from dependencies in Dart Sass](https://frontend.design-system.service.gov.uk/import-css/#simplify-sass-import-paths) guidance from GOV.UK Frontend. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
layout: layouts/get-started.njk | ||
subsection: Setup for production | ||
title: Import MoJ Frontend font and image assets | ||
eleventyNavigation: | ||
key: Import font and image assets | ||
parent: Setup for production | ||
order: 60 | ||
excerpt: "To use the font and image assets from MoJ Frontend and GOV.UK Frontend, you can either serve the assets from the combined assets folders or copy the font and image files into your application" | ||
--- | ||
|
||
To use the font and image assets from MoJ Frontend and GOV.UK Frontend, you can either: | ||
|
||
- serve the assets from the combined assets folders – recommended | ||
- copy the font and image files into your application | ||
|
||
## Serve the assets from the combined assets folders – recommended | ||
|
||
Set up your routing so requests for files in `<YOUR-SITE-URL>/assets` are served from both `/node_modules/govuk-frontend/dist/govuk/assets` and `/node_modules/@ministryofjustice/frontend/moj/assets`. | ||
|
||
For example if you’re using [express.js](https://expressjs.com/), add the following to your `app.js` file: | ||
|
||
```js | ||
router.use('/assets', [ | ||
express.static('node_modules/@ministryofjustice/frontend/moj/assets'), | ||
express.static('node_modules/govuk-frontend/dist/govuk/assets') | ||
]) | ||
``` | ||
|
||
## Copy the font and image files into your application | ||
|
||
If you decide to copy the assets instead, copy the: | ||
|
||
- `/node_modules/@ministryofjustice/frontend/moj/assets/images` contents to `<YOUR-APP>/assets/images` | ||
- `/node_modules/govuk-frontend/dist/govuk/assets/images` contents to `<YOUR-APP>/assets/images` | ||
- `/node_modules/govuk-frontend/dist/govuk/assets/fonts` contents to `<YOUR-APP>/assets/fonts` | ||
|
||
You should use an automated task or your build pipeline to copy the files, so your project folder stays up to date when updates to MoJ Frontend and GOV.UK Frontend are released. | ||
|
||
### If you have your own folder structure | ||
|
||
If you use a different folder structure than `<YOUR-APP>/assets/images` and `<YOUR-APP>/assets/fonts`, you can set Sass variables so that Sass builds the CSS to point to your folders. | ||
|
||
Set one of the following with a `@use` line in your Sass file: | ||
|
||
- `$govuk-assets-path` | ||
- `$govuk-images-path` and `$govuk-fonts-path` | ||
|
||
Set the `$govuk-assets-path` variable if your `font` and `image` folders have the same parent folder. For example: | ||
|
||
```scss | ||
// Configure GOV.UK Frontend | ||
@use "node_modules/govuk-frontend/dist/govuk" as * with ( | ||
$govuk-assets-path: "/<YOUR-ASSETS-FOLDER>/" | ||
); | ||
|
||
// Share config with MOJ Frontend | ||
@forward "node_modules/@ministryofjustice/frontend/moj/all" with ( | ||
$moj-assets-path: $govuk-assets-path | ||
); | ||
``` | ||
|
||
Set the `$govuk-images-path` and `$govuk-fonts-path` variables if your `font` and `image` folders have different parent folders. For example: | ||
|
||
```scss | ||
// Configure GOV.UK Frontend | ||
@use "node_modules/govuk-frontend/dist/govuk" as * with ( | ||
$govuk-images-path: "/<YOUR-IMAGES-FOLDER>/", | ||
$govuk-fonts-path: "/<YOUR-FONTS-FOLDER>/" | ||
); | ||
|
||
// Share config with MOJ Frontend | ||
@forward "node_modules/@ministryofjustice/frontend/moj/all" with ( | ||
$moj-images-path: $govuk-images-path, | ||
$moj-fonts-path: $govuk-fonts-path | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.