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

Update README and CHANGELOG for ES module bundle #3950

Merged
merged 4 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,28 @@ const Button = require('govuk-frontend/dist/govuk/components/button/button')
For example using `import`:

```mjs
import Button from 'govuk-frontend/dist/govuk-esm/components/button/button.mjs'
import Button from 'govuk-frontend/dist/govuk/components/button/button.mjs'
```

##### If you’re including JavaScript directly

Replace GOV.UK Frontend `all.js` with `govuk-frontend.min.js` and use `<script type="module">` for ES modules:

```html
<script type="module" src="{path-to-javascript}/govuk-frontend.min.js"></script>
```

Next replace `<script>window.GOVUKFrontend.initAll()</script>` to import and initialise GOV.UK Frontend using ES modules:

```html
<script type="module">
import { initAll } from '{path-to-javascript}/govuk-frontend.min.js'
initAll()
</script>
```

If you import JavaScript using a different method, you might need to make some changes. Refer to the [detailed guidance on importing JavaScript](https://frontend.design-system.service.gov.uk/importing-css-assets-and-javascript/#javascript).

##### If you’re using Sass

Replace `govuk-frontend/govuk` with `govuk-frontend/dist/govuk` in any [Sass](https://sass-lang.com/) `@import` paths.
Expand Down
15 changes: 9 additions & 6 deletions packages/govuk-frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,24 @@ To import add the below to your Sass file:

Some of the JavaScript included in GOV.UK Frontend improves the usability and
accessibility of the components. You should make sure that you are importing and
initialising Javascript in your application to ensure that all users can use it successfully.
initialising JavaScript in your application. This will ensure all users can use it successfully.

You can include Javascript for all components either by copying the `all.bundle.js` from `node_modules/govuk-frontend/dist/govuk/` into your application or referencing the file directly:
You can include JavaScript for all components by copying both `govuk-frontend.min.js` and `govuk-frontend.min.js.map` from `node_modules/govuk-frontend/dist/govuk/` into your application and referencing the JavaScript directly:

```html
<script type="module" src="<path-to-govuk-frontend-all-file>/all.bundle.js"></script>
<script type="module" src="{path-to-javascript}/govuk-frontend.min.js"></script>
```

Next you need to initialise the script by adding:
Next you need to import and initialise GOV.UK Frontend by adding:

```html
<script type="module">window.GOVUKFrontend.initAll()</script>
<script type="module">
import { initAll } from '{path-to-javascript}/govuk-frontend.min.js'
initAll()
</script>
```

[More details on importing Javascript and advanced options](https://frontend.design-system.service.gov.uk/importing-css-assets-and-javascript/#javascript)
[More details on importing JavaScript and advanced options](https://frontend.design-system.service.gov.uk/importing-css-assets-and-javascript/#javascript)

## Importing assets

Expand Down