ministryofjustice / moj-frontend

Use the MoJ Design System to design, build, and deliver accessible and consistent services.
https://design-patterns.service.justice.gov.uk/
MIT License
30 stars 18 forks source link

build(improvements) #602

Closed chrispymm closed 2 months ago

chrispymm commented 2 months ago

This PR updates the build pipeline to improve a few things:

Husky

The change to the husky config prevents double-prompting which occurs when git commit is aliased to git cz.

Drop Webpack

Previously there were 3 build tools 11ty, gulp, and webpack. With gulp handling the build & dist bundle of the package, 11ty handling the docs templates and webpack handling the docs site assets.

Webpack was mostly being used solely for copying files - which seems slightly overkill. Also using 3 tools was slow, and due to the parallel nature of the task would often result in multiple reloads. So this PR moves the tasks done by webpack to 11ty and gulp.

Dev reloading

Previously, changes to the src/component files would not be watched and picked up in the dev site, making local dev a bit slow.

This PR adds the ability to pass an ENV='dev' environment variable to 11ty, which modifies the nunjucks environment to look in the src/ directory for nunjucks templates. Allowing for 11ty to rebuild when a change is made to them.

The changes in this PR mean that now 11ty is responsible for watching and building the docs site assets, and gulp now has the build:docs task to copy the assets required for the site, and the watch:package task to watch for changes in the component scss and js files.

In order to achieve this, the assets directory has been moved within the docs directory, to place it within 11ty's watch scope.

Gulp does not copy across the all.js file from src, 11ty is configured to watch the all.js file. When gulp builds the package files, generating all.js this triggers an 11ty rebuild.

This means that now, any change to any .njk, .md, .js or .scss file will trigger a fast rebuild and reload of the site in dev.

gregtyler commented 1 month ago

:tada: This PR is included in version 2.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: