Closed tvararu closed 2 years ago
Found the solution:
esbuild index.js --bundle --resolve-extensions=.mjs,.js
It's the esbuild version of the same thing the guidance suggests for webpack: https://frontend.design-system.service.gov.uk/importing-css-assets-and-javascript/#import-javascript-using-a-bundler
From the esbuild docs https://esbuild.github.io/api/#resolve-extensions
Note that esbuild deliberately does not include the new .mjs and .cjs extensions in this list. Node's resolution algorithm doesn't treat these as implicit file extensions, so esbuild doesn't either. If you want to import files with these extensions you should either explicitly add the extensions in your import paths or change this setting to include the additional extensions that you want to be implicit.
Commit with green passing build: https://github.com/tvararu/govuk-frontend-esbuild-test/commit/0681217a81e9c8e5983490ebd68fcb56a8da63cd
Closing this issue, but happy I wrote this out for posterity or in case it helps others.
Maybe the govuk-frontend
docs could be updated to include a note about esbuild
, next to the webpack one?
Description of the issue
4.1.0
does not bundle successfully with esbuild.Steps to reproduce the issue
Minimal repro repository: https://github.com/tvararu/govuk-frontend-esbuild-test
Actual vs expected behaviour
See https://github.com/tvararu/govuk-frontend-esbuild-test/actions for a successful build with 4.0.1 vs a failing one with 4.1.0.
Example failing build output:
Environment (where applicable)