From 9deaf52afd6be5e1dc88d6a188a777efe509ba47 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Mon, 29 Apr 2024 16:58:50 +0100 Subject: [PATCH 01/10] Mark GOV.UK Frontend as free of side effects Any side effect affecting the global scope is encapsulated either in the components classes or initAll. By marking our package as free of side effects, WebPack drops any unused export appropriately --- packages/govuk-frontend/package.json | 1 + packages/govuk-frontend/package.json.unit.test.mjs | 12 ++++++++++++ .../govuk-frontend/tasks/build/package.unit.test.mjs | 1 + 3 files changed, 14 insertions(+) create mode 100644 packages/govuk-frontend/package.json.unit.test.mjs diff --git a/packages/govuk-frontend/package.json b/packages/govuk-frontend/package.json index 8a45157e13..136652d8de 100644 --- a/packages/govuk-frontend/package.json +++ b/packages/govuk-frontend/package.json @@ -23,6 +23,7 @@ "./govuk-prototype-kit.config.json": "./govuk-prototype-kit.config.json", "./package.json": "./package.json" }, + "sideEffects": false, "engines": { "node": ">= 4.2.0" }, diff --git a/packages/govuk-frontend/package.json.unit.test.mjs b/packages/govuk-frontend/package.json.unit.test.mjs new file mode 100644 index 0000000000..caac73133f --- /dev/null +++ b/packages/govuk-frontend/package.json.unit.test.mjs @@ -0,0 +1,12 @@ +import pkg from './package.json' + +describe('package.json', () => { + // The `sideEffects` field allows us to tell bundlers like Webpack or Rollup + // that they can safely delete code that's not being imported because our + // package has no code that executes when files are imported and modify the + // global environment, (JavaScript built-ins or the DOM). Everything is + // wrapped inside function or classes. + it('announces that our package has no side effects', () => { + expect(pkg.sideEffects).toBe(false) + }) +}) diff --git a/packages/govuk-frontend/tasks/build/package.unit.test.mjs b/packages/govuk-frontend/tasks/build/package.unit.test.mjs index ac9f606bda..d4414b19f9 100644 --- a/packages/govuk-frontend/tasks/build/package.unit.test.mjs +++ b/packages/govuk-frontend/tasks/build/package.unit.test.mjs @@ -151,6 +151,7 @@ describe('packages/govuk-frontend/dist/', () => { 'govuk-prototype-kit.config.json', 'gulpfile.mjs', 'package.json', + 'package.json.unit.test.mjs', 'postcss.config.mjs', 'postcss.config.unit.test.mjs', 'rollup.publish.config.mjs', From 69e8362a2e5d41634b9efa14a2d2df6865300540 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 14:24:43 +0100 Subject: [PATCH 02/10] Add bundler integrations script for Rollup --- .../bundler-integrations/package.json | 13 + .../bundler-integrations/rollup.config.mjs | 6 + .../bundler-integrations/src/index.mjs | 8 + package-lock.json | 293 +++++++++++------- package.json | 1 + 5 files changed, 201 insertions(+), 120 deletions(-) create mode 100644 .github/workflows/bundler-integrations/package.json create mode 100644 .github/workflows/bundler-integrations/rollup.config.mjs create mode 100644 .github/workflows/bundler-integrations/src/index.mjs diff --git a/.github/workflows/bundler-integrations/package.json b/.github/workflows/bundler-integrations/package.json new file mode 100644 index 0000000000..ce2968e8a4 --- /dev/null +++ b/.github/workflows/bundler-integrations/package.json @@ -0,0 +1,13 @@ +{ + "name": "@govuk-frontend/bundler-integrations", + "description": "Boilerplate to verify that GOV.UK Frontend works OK with main bundlers", + "private": true, + "scripts": { + "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "rollup": "^4.17.2", + "govuk-frontend": "*" + } +} diff --git a/.github/workflows/bundler-integrations/rollup.config.mjs b/.github/workflows/bundler-integrations/rollup.config.mjs new file mode 100644 index 0000000000..6ad8acfef7 --- /dev/null +++ b/.github/workflows/bundler-integrations/rollup.config.mjs @@ -0,0 +1,6 @@ +import resolve from '@rollup/plugin-node-resolve' + +/** @type {import('rollup').RollupOptions} */ +export default { + plugins: [resolve()] +} diff --git a/.github/workflows/bundler-integrations/src/index.mjs b/.github/workflows/bundler-integrations/src/index.mjs new file mode 100644 index 0000000000..9a45823853 --- /dev/null +++ b/.github/workflows/bundler-integrations/src/index.mjs @@ -0,0 +1,8 @@ +import { Button } from 'govuk-frontend' + +const $buttons = document.querySelectorAll('[data-module="govuk-button"]') + +$buttons.forEach(($button) => { + /* eslint-disable-next-line no-new */ + new Button($button) +}) diff --git a/package-lock.json b/package-lock.json index a340bf5db0..890fc7f766 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "license": "MIT", "workspaces": [ ".github/workflows/scripts", + ".github/workflows/bundler-integrations", "packages/govuk-frontend", "packages/govuk-frontend-review", "shared/*", @@ -79,6 +80,14 @@ "typed-query-selector": "^2.11.2" } }, + ".github/workflows/bundler-integrations": { + "name": "@govuk-frontend/bundler-integrations", + "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "govuk-frontend": "*", + "rollup": "^4.17.2" + } + }, ".github/workflows/scripts": { "name": "@govuk-frontend/workflow-scripts", "license": "MIT", @@ -92,6 +101,28 @@ "npm": "^10.1.0" } }, + "docs/examples/rollup": { + "name": "@govuk-frontend/rollup-boilerplate", + "extraneous": true, + "dependencies": { + "govuk-frontend": "*" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "rollup": "^4.17.1" + } + }, + "docs/examples/vite": { + "name": "@govuk-frontend/vite-boilerplate", + "extraneous": true, + "dependencies": { + "govuk-frontend": "*" + }, + "devDependencies": { + "del-cli": "^5.1.0", + "vite": "^5.2.10" + } + }, "docs/examples/webpack": { "name": "@govuk-frontend/webpack-boilerplate", "dependencies": { @@ -2204,6 +2235,10 @@ "node": ">=14" } }, + "node_modules/@govuk-frontend/bundler-integrations": { + "resolved": ".github/workflows/bundler-integrations", + "link": true + }, "node_modules/@govuk-frontend/config": { "resolved": "shared/config", "link": true @@ -4150,9 +4185,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.13.2.tgz", - "integrity": "sha512-3XFIDKWMFZrMnao1mJhnOT1h2g0169Os848NhhmGweEcfJ4rCi+3yMCOLG4zA61rbJdkcrM/DjVZm9Hg5p5w7g==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.17.2.tgz", + "integrity": "sha512-NM0jFxY8bB8QLkoKxIQeObCaDlJKewVlIEkuyYKm5An1tdVZ966w2+MPQ2l8LBZLjR+SgyV+nRkTIunzOYBMLQ==", "cpu": [ "arm" ], @@ -4163,9 +4198,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.13.2.tgz", - "integrity": "sha512-GdxxXbAuM7Y/YQM9/TwwP+L0omeE/lJAR1J+olu36c3LqqZEBdsIWeQ91KBe6nxwOnb06Xh7JS2U5ooWU5/LgQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.17.2.tgz", + "integrity": "sha512-yeX/Usk7daNIVwkq2uGoq2BYJKZY1JfyLTaHO/jaiSwi/lsf8fTFoQW/n6IdAsx5tx+iotu2zCJwz8MxI6D/Bw==", "cpu": [ "arm64" ], @@ -4176,9 +4211,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.13.2.tgz", - "integrity": "sha512-mCMlpzlBgOTdaFs83I4XRr8wNPveJiJX1RLfv4hggyIVhfB5mJfN4P8Z6yKh+oE4Luz+qq1P3kVdWrCKcMYrrA==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.17.2.tgz", + "integrity": "sha512-kcMLpE6uCwls023+kknm71ug7MZOrtXo+y5p/tsg6jltpDtgQY1Eq5sGfHcQfb+lfuKwhBmEURDga9N0ol4YPw==", "cpu": [ "arm64" ], @@ -4189,9 +4224,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.13.2.tgz", - "integrity": "sha512-yUoEvnH0FBef/NbB1u6d3HNGyruAKnN74LrPAfDQL3O32e3k3OSfLrPgSJmgb3PJrBZWfPyt6m4ZhAFa2nZp2A==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.17.2.tgz", + "integrity": "sha512-AtKwD0VEx0zWkL0ZjixEkp5tbNLzX+FCqGG1SvOu993HnSz4qDI6S4kGzubrEJAljpVkhRSlg5bzpV//E6ysTQ==", "cpu": [ "x64" ], @@ -4202,9 +4237,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.13.2.tgz", - "integrity": "sha512-GYbLs5ErswU/Xs7aGXqzc3RrdEjKdmoCrgzhJWyFL0r5fL3qd1NPcDKDowDnmcoSiGJeU68/Vy+OMUluRxPiLQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.17.2.tgz", + "integrity": "sha512-3reX2fUHqN7sffBNqmEyMQVj/CKhIHZd4y631duy0hZqI8Qoqf6lTtmAKvJFYa6bhU95B1D0WgzHkmTg33In0A==", "cpu": [ "arm" ], @@ -4215,9 +4250,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.13.2.tgz", - "integrity": "sha512-L1+D8/wqGnKQIlh4Zre9i4R4b4noxzH5DDciyahX4oOz62CphY7WDWqJoQ66zNR4oScLNOqQJfNSIAe/6TPUmQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.17.2.tgz", + "integrity": "sha512-EMMPHkiCRtE8Wdk3Qhtciq6BndLtstqZIroHiiGzB3C5LDJmIZcSzVtLRbwuXuUft1Cnv+9fxuDtDxz3k3EW2A==", "cpu": [ "arm64" ], @@ -4228,9 +4263,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.13.2.tgz", - "integrity": "sha512-tK5eoKFkXdz6vjfkSTCupUzCo40xueTOiOO6PeEIadlNBkadH1wNOH8ILCPIl8by/Gmb5AGAeQOFeLev7iZDOA==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.17.2.tgz", + "integrity": "sha512-NMPylUUZ1i0z/xJUIx6VUhISZDRT+uTWpBcjdv0/zkp7b/bQDF+NfnfdzuTiB1G6HTodgoFa93hp0O1xl+/UbA==", "cpu": [ "arm64" ], @@ -4241,11 +4276,11 @@ ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.13.2.tgz", - "integrity": "sha512-zvXvAUGGEYi6tYhcDmb9wlOckVbuD+7z3mzInCSTACJ4DQrdSLPNUeDIcAQW39M3q6PDquqLWu7pnO39uSMRzQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.17.2.tgz", + "integrity": "sha512-T19My13y8uYXPw/L/k0JYaX1fJKFT/PWdXiHr8mTbXWxjVF1t+8Xl31DgBBvEKclw+1b00Chg0hxE2O7bTG7GQ==", "cpu": [ - "ppc64le" + "ppc64" ], "dev": true, "optional": true, @@ -4254,9 +4289,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.13.2.tgz", - "integrity": "sha512-C3GSKvMtdudHCN5HdmAMSRYR2kkhgdOfye4w0xzyii7lebVr4riCgmM6lRiSCnJn2w1Xz7ZZzHKuLrjx5620kw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.17.2.tgz", + "integrity": "sha512-BOaNfthf3X3fOWAB+IJ9kxTgPmMqPPH5f5k2DcCsRrBIbWnaJCgX2ll77dV1TdSy9SaXTR5iDXRL8n7AnoP5cg==", "cpu": [ "riscv64" ], @@ -4267,9 +4302,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.13.2.tgz", - "integrity": "sha512-l4U0KDFwzD36j7HdfJ5/TveEQ1fUTjFFQP5qIt9gBqBgu1G8/kCaq5Ok05kd5TG9F8Lltf3MoYsUMw3rNlJ0Yg==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.17.2.tgz", + "integrity": "sha512-W0UP/x7bnn3xN2eYMql2T/+wpASLE5SjObXILTMPUBDB/Fg/FxC+gX4nvCfPBCbNhz51C+HcqQp2qQ4u25ok6g==", "cpu": [ "s390x" ], @@ -4280,9 +4315,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.13.2.tgz", - "integrity": "sha512-xXMLUAMzrtsvh3cZ448vbXqlUa7ZL8z0MwHp63K2IIID2+DeP5iWIT6g1SN7hg1VxPzqx0xZdiDM9l4n9LRU1A==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.17.2.tgz", + "integrity": "sha512-Hy7pLwByUOuyaFC6mAr7m+oMC+V7qyifzs/nW2OJfC8H4hbCzOX07Ov0VFk/zP3kBsELWNFi7rJtgbKYsav9QQ==", "cpu": [ "x64" ], @@ -4293,9 +4328,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.13.2.tgz", - "integrity": "sha512-M/JYAWickafUijWPai4ehrjzVPKRCyDb1SLuO+ZyPfoXgeCEAlgPkNXewFZx0zcnoIe3ay4UjXIMdXQXOZXWqA==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.17.2.tgz", + "integrity": "sha512-h1+yTWeYbRdAyJ/jMiVw0l6fOOm/0D1vNLui9iPuqgRGnXA0u21gAqOyB5iHjlM9MMfNOm9RHCQ7zLIzT0x11Q==", "cpu": [ "x64" ], @@ -4306,9 +4341,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.13.2.tgz", - "integrity": "sha512-2YWwoVg9KRkIKaXSh0mz3NmfurpmYoBBTAXA9qt7VXk0Xy12PoOP40EFuau+ajgALbbhi4uTj3tSG3tVseCjuA==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.17.2.tgz", + "integrity": "sha512-tmdtXMfKAjy5+IQsVtDiCfqbynAQE/TQRpWdVataHmhMb9DCoJxp9vLcCBjEQWMiUYxO1QprH/HbY9ragCEFLA==", "cpu": [ "arm64" ], @@ -4319,9 +4354,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.13.2.tgz", - "integrity": "sha512-2FSsE9aQ6OWD20E498NYKEQLneShWes0NGMPQwxWOdws35qQXH+FplabOSP5zEe1pVjurSDOGEVCE2agFwSEsw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.17.2.tgz", + "integrity": "sha512-7II/QCSTAHuE5vdZaQEwJq2ZACkBpQDOmQsE6D6XUbnBHW8IAhm4eTufL6msLJorzrHDFv3CF8oCA/hSIRuZeQ==", "cpu": [ "ia32" ], @@ -4332,9 +4367,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.13.2.tgz", - "integrity": "sha512-7h7J2nokcdPePdKykd8wtc8QqqkqxIrUz7MHj6aNr8waBRU//NLDVnNjQnqQO6fqtjrtCdftpbTuOKAyrAQETQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.17.2.tgz", + "integrity": "sha512-TGGO7v7qOq4CYmSBVEYpI1Y5xDuCEnbVC5Vth8mOsW0gDSzxNrVERPc790IGHsrT2dQSimgMr9Ub3Y1Jci5/8w==", "cpu": [ "x64" ], @@ -5339,9 +5374,9 @@ "dev": true }, "node_modules/@webassemblyjs/ast": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", - "integrity": "sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.12.1.tgz", + "integrity": "sha512-EKfMUOPRRUTy5UII4qJDGPpqfwjOmZ5jeGFwid9mnoqIFK+e0vqoi1qH56JpmZSzEL53jKnNzScdmftJyG5xWg==", "dev": true, "dependencies": { "@webassemblyjs/helper-numbers": "1.11.6", @@ -5361,9 +5396,9 @@ "dev": true }, "node_modules/@webassemblyjs/helper-buffer": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz", - "integrity": "sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.12.1.tgz", + "integrity": "sha512-nzJwQw99DNDKr9BVCOZcLuJJUlqkJh+kVzVl6Fmq/tI5ZtEyWT1KZMyOXltXLZJmDtvLCDgwsyrkohEtopTXCw==", "dev": true }, "node_modules/@webassemblyjs/helper-numbers": { @@ -5384,15 +5419,15 @@ "dev": true }, "node_modules/@webassemblyjs/helper-wasm-section": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz", - "integrity": "sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.12.1.tgz", + "integrity": "sha512-Jif4vfB6FJlUlSbgEMHUyk1j234GTNG9dBJ4XJdOySoj518Xj0oGsNi59cUQF4RRMS9ouBUxDDdyBVfPTypa5g==", "dev": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/helper-buffer": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6" + "@webassemblyjs/wasm-gen": "1.12.1" } }, "node_modules/@webassemblyjs/ieee754": { @@ -5420,28 +5455,28 @@ "dev": true }, "node_modules/@webassemblyjs/wasm-edit": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz", - "integrity": "sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.12.1.tgz", + "integrity": "sha512-1DuwbVvADvS5mGnXbE+c9NfA8QRcZ6iKquqjjmR10k6o+zzsRVesil54DKexiowcFCPdr/Q0qaMgB01+SQ1u6g==", "dev": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/helper-buffer": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/helper-wasm-section": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6", - "@webassemblyjs/wasm-opt": "1.11.6", - "@webassemblyjs/wasm-parser": "1.11.6", - "@webassemblyjs/wast-printer": "1.11.6" + "@webassemblyjs/helper-wasm-section": "1.12.1", + "@webassemblyjs/wasm-gen": "1.12.1", + "@webassemblyjs/wasm-opt": "1.12.1", + "@webassemblyjs/wasm-parser": "1.12.1", + "@webassemblyjs/wast-printer": "1.12.1" } }, "node_modules/@webassemblyjs/wasm-gen": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz", - "integrity": "sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.12.1.tgz", + "integrity": "sha512-TDq4Ojh9fcohAw6OIMXqiIcTq5KUXTGRkVxbSo1hQnSy6lAM5GSdfwWeSxpAo0YzgsgF182E/U0mDNhuA0tW7w==", "dev": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", "@webassemblyjs/ieee754": "1.11.6", "@webassemblyjs/leb128": "1.11.6", @@ -5449,24 +5484,24 @@ } }, "node_modules/@webassemblyjs/wasm-opt": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz", - "integrity": "sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.12.1.tgz", + "integrity": "sha512-Jg99j/2gG2iaz3hijw857AVYekZe2SAskcqlWIZXjji5WStnOpVoat3gQfT/Q5tb2djnCjBtMocY/Su1GfxPBg==", "dev": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6", - "@webassemblyjs/wasm-parser": "1.11.6" + "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/helper-buffer": "1.12.1", + "@webassemblyjs/wasm-gen": "1.12.1", + "@webassemblyjs/wasm-parser": "1.12.1" } }, "node_modules/@webassemblyjs/wasm-parser": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz", - "integrity": "sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.12.1.tgz", + "integrity": "sha512-xikIi7c2FHXysxXe3COrVUPSheuBtpcfhbpFj4gmu7KRLYOzANztwUU0IbsqvMqzuNK2+glRGWCEqZo1WCLyAQ==", "dev": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-api-error": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", "@webassemblyjs/ieee754": "1.11.6", @@ -5475,12 +5510,12 @@ } }, "node_modules/@webassemblyjs/wast-printer": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz", - "integrity": "sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.12.1.tgz", + "integrity": "sha512-+X4WAlOisVWQMikjbcvY2e0rwPsKQ9F688lksZhBcPycBBuii3O7m8FACbDMWDojpAqvjIncrG8J0XHKyQfVeA==", "dev": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/ast": "1.12.1", "@xtuc/long": "4.2.2" } }, @@ -10542,9 +10577,9 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.15.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", - "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.16.0.tgz", + "integrity": "sha512-O+QWCviPNSSLAD9Ucn8Awv+poAkqn3T1XY5/N7kR7rQO9yfSGWkYZDwpJ+iKF7B8rxaQKWngSqACpgzeapSyoA==", "dev": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -24830,9 +24865,9 @@ } }, "node_modules/rollup": { - "version": "4.13.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.13.2.tgz", - "integrity": "sha512-MIlLgsdMprDBXC+4hsPgzWUasLO9CE4zOkj/u6j+Z6j5A4zRY+CtiXAdJyPtgCsc42g658Aeh1DlrdVEJhsL2g==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.17.2.tgz", + "integrity": "sha512-/9ClTJPByC0U4zNLowV1tMBe8yMEAxewtR3cUNX5BoEpGH3dQEWpJLr6CLp0fPdYRF/fzVOgvDb1zXuakwF5kQ==", "dev": true, "dependencies": { "@types/estree": "1.0.5" @@ -24845,21 +24880,22 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.13.2", - "@rollup/rollup-android-arm64": "4.13.2", - "@rollup/rollup-darwin-arm64": "4.13.2", - "@rollup/rollup-darwin-x64": "4.13.2", - "@rollup/rollup-linux-arm-gnueabihf": "4.13.2", - "@rollup/rollup-linux-arm64-gnu": "4.13.2", - "@rollup/rollup-linux-arm64-musl": "4.13.2", - "@rollup/rollup-linux-powerpc64le-gnu": "4.13.2", - "@rollup/rollup-linux-riscv64-gnu": "4.13.2", - "@rollup/rollup-linux-s390x-gnu": "4.13.2", - "@rollup/rollup-linux-x64-gnu": "4.13.2", - "@rollup/rollup-linux-x64-musl": "4.13.2", - "@rollup/rollup-win32-arm64-msvc": "4.13.2", - "@rollup/rollup-win32-ia32-msvc": "4.13.2", - "@rollup/rollup-win32-x64-msvc": "4.13.2", + "@rollup/rollup-android-arm-eabi": "4.17.2", + "@rollup/rollup-android-arm64": "4.17.2", + "@rollup/rollup-darwin-arm64": "4.17.2", + "@rollup/rollup-darwin-x64": "4.17.2", + "@rollup/rollup-linux-arm-gnueabihf": "4.17.2", + "@rollup/rollup-linux-arm-musleabihf": "4.17.2", + "@rollup/rollup-linux-arm64-gnu": "4.17.2", + "@rollup/rollup-linux-arm64-musl": "4.17.2", + "@rollup/rollup-linux-powerpc64le-gnu": "4.17.2", + "@rollup/rollup-linux-riscv64-gnu": "4.17.2", + "@rollup/rollup-linux-s390x-gnu": "4.17.2", + "@rollup/rollup-linux-x64-gnu": "4.17.2", + "@rollup/rollup-linux-x64-musl": "4.17.2", + "@rollup/rollup-win32-arm64-msvc": "4.17.2", + "@rollup/rollup-win32-ia32-msvc": "4.17.2", + "@rollup/rollup-win32-x64-msvc": "4.17.2", "fsevents": "~2.3.2" } }, @@ -24898,6 +24934,19 @@ "node": ">= 8" } }, + "node_modules/rollup/node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.17.2.tgz", + "integrity": "sha512-uSqpsp91mheRgw96xtyAGP9FW5ChctTFEoXP0r5FAzj/3ZRv3Uxjtc7taRQSaQM/q85KEKjKsZuiZM3GyUivRg==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, "node_modules/run-applescript": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz", @@ -29923,9 +29972,9 @@ } }, "node_modules/watchpack": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", - "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.1.tgz", + "integrity": "sha512-8wrBCMtVhqcXP2Sup1ctSkga6uc2Bx0IIvKyT7yTFier5AXHooSI+QyQQAtTb7+E0IUCCKyTFmXqdqgum2XWGg==", "dev": true, "dependencies": { "glob-to-regexp": "^0.4.1", @@ -29954,26 +30003,26 @@ } }, "node_modules/webpack": { - "version": "5.90.3", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.90.3.tgz", - "integrity": "sha512-h6uDYlWCctQRuXBs1oYpVe6sFcWedl0dpcVaTf/YF67J9bKvwJajFulMVSYKHrksMB3I/pIagRzDxwxkebuzKA==", + "version": "5.91.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.91.0.tgz", + "integrity": "sha512-rzVwlLeBWHJbmgTC/8TvAcu5vpJNII+MelQpylD4jNERPwpBJOE2lEcko1zJX3QJeLjTTAnQxn/OJ8bjDzVQaw==", "dev": true, "dependencies": { "@types/eslint-scope": "^3.7.3", "@types/estree": "^1.0.5", - "@webassemblyjs/ast": "^1.11.5", - "@webassemblyjs/wasm-edit": "^1.11.5", - "@webassemblyjs/wasm-parser": "^1.11.5", + "@webassemblyjs/ast": "^1.12.1", + "@webassemblyjs/wasm-edit": "^1.12.1", + "@webassemblyjs/wasm-parser": "^1.12.1", "acorn": "^8.7.1", "acorn-import-assertions": "^1.9.0", "browserslist": "^4.21.10", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.15.0", + "enhanced-resolve": "^5.16.0", "es-module-lexer": "^1.2.1", "eslint-scope": "5.1.1", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.2.9", + "graceful-fs": "^4.2.11", "json-parse-even-better-errors": "^2.3.1", "loader-runner": "^4.2.0", "mime-types": "^2.1.27", @@ -29981,7 +30030,7 @@ "schema-utils": "^3.2.0", "tapable": "^2.1.1", "terser-webpack-plugin": "^5.3.10", - "watchpack": "^2.4.0", + "watchpack": "^2.4.1", "webpack-sources": "^3.2.3" }, "bin": { @@ -30948,6 +30997,10 @@ "node": ">=8" } }, + "shared/bundler-integrations": { + "name": "@govuk-frontend/bundler-integrations", + "extraneous": true + }, "shared/config": { "name": "@govuk-frontend/config", "license": "MIT", diff --git a/package.json b/package.json index 94c73213b4..5445012332 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "license": "MIT", "workspaces": [ ".github/workflows/scripts", + ".github/workflows/bundler-integrations", "packages/govuk-frontend", "packages/govuk-frontend-review", "shared/*", From 2b5444d722341c3a84065966276871f9e4b01fbc Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 14:38:35 +0100 Subject: [PATCH 03/10] Add bundler integration for Webpack --- .github/workflows/bundler-integrations/package.json | 6 ++++-- .../workflows/bundler-integrations/webpack.config.js | 11 +++++++++++ package-lock.json | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/bundler-integrations/webpack.config.js diff --git a/.github/workflows/bundler-integrations/package.json b/.github/workflows/bundler-integrations/package.json index ce2968e8a4..8253232b7b 100644 --- a/.github/workflows/bundler-integrations/package.json +++ b/.github/workflows/bundler-integrations/package.json @@ -3,11 +3,13 @@ "description": "Boilerplate to verify that GOV.UK Frontend works OK with main bundlers", "private": true, "scripts": { - "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js" + "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js", + "webpack": "webpack ./src/index.mjs --mode production -o dist/webpack" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", + "govuk-frontend": "*", "rollup": "^4.17.2", - "govuk-frontend": "*" + "webpack": "^5.91.0" } } diff --git a/.github/workflows/bundler-integrations/webpack.config.js b/.github/workflows/bundler-integrations/webpack.config.js new file mode 100644 index 0000000000..1919395560 --- /dev/null +++ b/.github/workflows/bundler-integrations/webpack.config.js @@ -0,0 +1,11 @@ +/** @type {import('webpack').Configuration} */ +module.exports = { + optimization: { + // Configure WebPack to drop exports that are not used from the code + // so we can disable Terser and still check what's being included + usedExports: true, + // Prevent minification so we can see what's going on in the built file + minimize: false + }, + target: 'web' +} diff --git a/package-lock.json b/package-lock.json index 890fc7f766..2570740504 100644 --- a/package-lock.json +++ b/package-lock.json @@ -85,7 +85,8 @@ "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", "govuk-frontend": "*", - "rollup": "^4.17.2" + "rollup": "^4.17.2", + "webpack": "^5.91.0" } }, ".github/workflows/scripts": { From 462b57b814de648d7a2a618d51efcb03277c3ca2 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 15:00:31 +0100 Subject: [PATCH 04/10] Add vite bundler integration script --- .../workflows/bundler-integrations/index.html | 12 + .../bundler-integrations/package.json | 4 +- .../bundler-integrations/vite.config.mjs | 10 + package-lock.json | 462 ++++++++++++++++++ 4 files changed, 487 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/bundler-integrations/index.html create mode 100644 .github/workflows/bundler-integrations/vite.config.mjs diff --git a/.github/workflows/bundler-integrations/index.html b/.github/workflows/bundler-integrations/index.html new file mode 100644 index 0000000000..a719560f0f --- /dev/null +++ b/.github/workflows/bundler-integrations/index.html @@ -0,0 +1,12 @@ + + + + + + Vite entry point + + + + + + diff --git a/.github/workflows/bundler-integrations/package.json b/.github/workflows/bundler-integrations/package.json index 8253232b7b..b149dd13e0 100644 --- a/.github/workflows/bundler-integrations/package.json +++ b/.github/workflows/bundler-integrations/package.json @@ -4,12 +4,14 @@ "private": true, "scripts": { "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js", - "webpack": "webpack ./src/index.mjs --mode production -o dist/webpack" + "webpack": "webpack ./src/index.mjs --mode production -o dist/webpack", + "vite": "vite build" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", "govuk-frontend": "*", "rollup": "^4.17.2", + "vite": "^5.2.10", "webpack": "^5.91.0" } } diff --git a/.github/workflows/bundler-integrations/vite.config.mjs b/.github/workflows/bundler-integrations/vite.config.mjs new file mode 100644 index 0000000000..65c7b4c9fa --- /dev/null +++ b/.github/workflows/bundler-integrations/vite.config.mjs @@ -0,0 +1,10 @@ +/** @type {import('vite').UserConfig} */ +export default { + build: { + // Align output with other bundlers to facilitate testing + outDir: 'dist/vite', + assetsDir: '.', + // Prevent minification so we can see actual class/function names + minify: false + } +} diff --git a/package-lock.json b/package-lock.json index 2570740504..f3eb801377 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,6 +86,7 @@ "@rollup/plugin-node-resolve": "^15.2.3", "govuk-frontend": "*", "rollup": "^4.17.2", + "vite": "^5.2.10", "webpack": "^5.91.0" } }, @@ -2100,6 +2101,374 @@ "node": ">=16" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz", + "integrity": "sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.2.tgz", + "integrity": "sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.2.tgz", + "integrity": "sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.2.tgz", + "integrity": "sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.2.tgz", + "integrity": "sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz", + "integrity": "sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.2.tgz", + "integrity": "sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.2.tgz", + "integrity": "sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.2.tgz", + "integrity": "sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.2.tgz", + "integrity": "sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.2.tgz", + "integrity": "sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.2.tgz", + "integrity": "sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.2.tgz", + "integrity": "sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.2.tgz", + "integrity": "sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.2.tgz", + "integrity": "sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.2.tgz", + "integrity": "sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz", + "integrity": "sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.2.tgz", + "integrity": "sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.2.tgz", + "integrity": "sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.2.tgz", + "integrity": "sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.2.tgz", + "integrity": "sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.2.tgz", + "integrity": "sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz", + "integrity": "sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -10813,6 +11182,44 @@ "es6-symbol": "^3.1.1" } }, + "node_modules/esbuild": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz", + "integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.20.2", + "@esbuild/android-arm": "0.20.2", + "@esbuild/android-arm64": "0.20.2", + "@esbuild/android-x64": "0.20.2", + "@esbuild/darwin-arm64": "0.20.2", + "@esbuild/darwin-x64": "0.20.2", + "@esbuild/freebsd-arm64": "0.20.2", + "@esbuild/freebsd-x64": "0.20.2", + "@esbuild/linux-arm": "0.20.2", + "@esbuild/linux-arm64": "0.20.2", + "@esbuild/linux-ia32": "0.20.2", + "@esbuild/linux-loong64": "0.20.2", + "@esbuild/linux-mips64el": "0.20.2", + "@esbuild/linux-ppc64": "0.20.2", + "@esbuild/linux-riscv64": "0.20.2", + "@esbuild/linux-s390x": "0.20.2", + "@esbuild/linux-x64": "0.20.2", + "@esbuild/netbsd-x64": "0.20.2", + "@esbuild/openbsd-x64": "0.20.2", + "@esbuild/sunos-x64": "0.20.2", + "@esbuild/win32-arm64": "0.20.2", + "@esbuild/win32-ia32": "0.20.2", + "@esbuild/win32-x64": "0.20.2" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -29920,6 +30327,61 @@ "node": ">= 0.9" } }, + "node_modules/vite": { + "version": "5.2.10", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.2.10.tgz", + "integrity": "sha512-PAzgUZbP7msvQvqdSD+ErD5qGnSFiGOoWmV5yAKUEI0kdhjbH6nMWVyZQC/hSc4aXwc0oJ9aEdIiF9Oje0JFCw==", + "dev": true, + "dependencies": { + "esbuild": "^0.20.1", + "postcss": "^8.4.38", + "rollup": "^4.13.0" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^18.0.0 || >=20.0.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^18.0.0 || >=20.0.0", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.4.0" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + } + } + }, "node_modules/vscode-oniguruma": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz", From 37d73e86b71069e1a23780f99e77d4a33460d662 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 16:03:52 +0100 Subject: [PATCH 05/10] Add GitHub workflow for checking integration with bundlers --- .github/workflows/bundler-integrations.yml | 41 ++++++++++++++++++++++ .github/workflows/tests.yml | 8 +++++ 2 files changed, 49 insertions(+) create mode 100644 .github/workflows/bundler-integrations.yml diff --git a/.github/workflows/bundler-integrations.yml b/.github/workflows/bundler-integrations.yml new file mode 100644 index 0000000000..e3231ab151 --- /dev/null +++ b/.github/workflows/bundler-integrations.yml @@ -0,0 +1,41 @@ +name: Bundler integrations + +on: + workflow_call: + workflow_dispatch: + +jobs: + test-tree-shaking: + name: Test tree shaking + runs-on: ubuntu-latest + + env: + PUPPETEER_SKIP_DOWNLOAD: true + + strategy: + fail-fast: false + + matrix: + bundler: + - rollup + - webpack + - vite + + steps: + - name: Checkout + uses: actions/checkout@v4.1.4 + + - name: Restore dependencies + uses: ./.github/workflows/actions/install-node + + - name: Build GOV.UK Frontend + uses: ./.github/workflows/actions/build + + - name: Build with bundler + run: npm run ${{matrix.bundler}} -w @govuk-frontend/bundler-integrations + + # Check output for modules that should not be included + - name: Check output + working-directory: ./.github/workflows/bundler-integrations + run: | + ! grep "Accordion" dist/${{matrix.bundler}}/*.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8c013a27fc..34b7de638f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -324,3 +324,11 @@ jobs: # Run existing "Stats comment" workflow # (after only install has been cached) uses: ./.github/workflows/stats-comment.yml + + bundler-integrations: + name: Bundler integrations + needs: [install, build] + + # Run existing "Bundler integrations" workflow + # (after install and build have been cached) + uses: ./.github/workflows/bundler-integrations.yml From f66050901d7679b3c01d04727fde1ae9f19d3922 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 16:59:29 +0100 Subject: [PATCH 06/10] Add clean script to bundler integrations workspace Ensures the documentation for running 'npm run clean' without specifying a workspace remains true --- .github/workflows/bundler-integrations/package.json | 4 +++- package-lock.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bundler-integrations/package.json b/.github/workflows/bundler-integrations/package.json index b149dd13e0..f072fe6868 100644 --- a/.github/workflows/bundler-integrations/package.json +++ b/.github/workflows/bundler-integrations/package.json @@ -5,10 +5,12 @@ "scripts": { "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js", "webpack": "webpack ./src/index.mjs --mode production -o dist/webpack", - "vite": "vite build" + "vite": "vite build", + "clean": "del-cli dist" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", + "del-cli": "^5.1.0", "govuk-frontend": "*", "rollup": "^4.17.2", "vite": "^5.2.10", diff --git a/package-lock.json b/package-lock.json index f3eb801377..e313fce5db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -84,6 +84,7 @@ "name": "@govuk-frontend/bundler-integrations", "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", + "del-cli": "^5.1.0", "govuk-frontend": "*", "rollup": "^4.17.2", "vite": "^5.2.10", From 80b0329252006087e010b2a05fdbc6f2d3932e58 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 17:13:09 +0100 Subject: [PATCH 07/10] Add script to run all bundler integrations at once Called `build:all`, not `build` so it doesn't get run by `npm run build --workspaces` on CI (in `.github/workflows/actions/build/action.yml`). If called `build` it would run before `govuk-frontend` gets build and the build would fail. --- .github/workflows/bundler-integrations/package.json | 4 +++- package-lock.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bundler-integrations/package.json b/.github/workflows/bundler-integrations/package.json index f072fe6868..a3025c1803 100644 --- a/.github/workflows/bundler-integrations/package.json +++ b/.github/workflows/bundler-integrations/package.json @@ -6,10 +6,12 @@ "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js", "webpack": "webpack ./src/index.mjs --mode production -o dist/webpack", "vite": "vite build", - "clean": "del-cli dist" + "clean": "del-cli dist", + "build:all": "concurrently \"npm run rollup\" \"npm run webpack\" \"npm run vite\" --names \"rollup,webpack,vite\" --prefix-colors \"red.dim,blue.dim,yellow.dim\"" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", + "concurrently": "^8.2.2", "del-cli": "^5.1.0", "govuk-frontend": "*", "rollup": "^4.17.2", diff --git a/package-lock.json b/package-lock.json index e313fce5db..45bd33bd72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -84,6 +84,7 @@ "name": "@govuk-frontend/bundler-integrations", "devDependencies": { "@rollup/plugin-node-resolve": "^15.2.3", + "concurrently": "^8.2.2", "del-cli": "^5.1.0", "govuk-frontend": "*", "rollup": "^4.17.2", From 604182a4c313e276ee40190d67187022d453adaa Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 30 Apr 2024 17:14:20 +0100 Subject: [PATCH 08/10] Document npm tasks for bundler integrations --- docs/contributing/tasks.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/contributing/tasks.md b/docs/contributing/tasks.md index 89bc2507bd..50256e291a 100644 --- a/docs/contributing/tasks.md +++ b/docs/contributing/tasks.md @@ -99,3 +99,13 @@ This task will: ## Review app only After building the project with `npm run build` the Express.js review app can be started with `npm start --workspace @govuk-frontend/review`. This prevents the Gulp tasks triggered by `npm start` from running. + +## Bundler integration + +After building the project with `npm run build`, you can verify that the `govuk-frontend` package will be consumed correctly by mainstream bundlers with `npm run --workspace @govuk-frontend/bundler-integrations` (where bundler name is one of `rollup`, `webpack` or `vite`). + +This will use the specified bundler to compile `.github/workflows/bundler-integrations/src/index.mjs`. That file only imports one components, which will let us verify that [tree shaking] works as intended. The build output (in `.github/workflows/bundler-integrations/dist//`) should not contain the code of other components. + +You can also run `npm run build:all --workspace @govuk-frontend/bundler-integrations` to run all three bundlers in one go. + +[tree shaking]: https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking From 775a3a7748d8bd5496a9d1e5f4dee1d45294746b Mon Sep 17 00:00:00 2001 From: Owen Jones Date: Wed, 1 May 2024 17:13:05 +0100 Subject: [PATCH 09/10] Amend bundle tests to also test against `initAll` importing This ensures that any changes we make to our importing process don't negatively impact users who're importing via `initAll` --- .github/workflows/bundler-integrations.yml | 3 ++- .github/workflows/bundler-integrations/index.html | 12 ------------ .github/workflows/bundler-integrations/package.json | 7 +++++-- .../workflows/bundler-integrations/src/initAll.mjs | 4 ++++ .../src/{index.mjs => single-component.mjs} | 1 + .../workflows/bundler-integrations/vite.config.mjs | 10 +++++++++- .../workflows/bundler-integrations/webpack.config.js | 9 ++++++++- docs/contributing/tasks.md | 2 +- 8 files changed, 30 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/bundler-integrations/index.html create mode 100644 .github/workflows/bundler-integrations/src/initAll.mjs rename .github/workflows/bundler-integrations/src/{index.mjs => single-component.mjs} (71%) diff --git a/.github/workflows/bundler-integrations.yml b/.github/workflows/bundler-integrations.yml index e3231ab151..97736647ed 100644 --- a/.github/workflows/bundler-integrations.yml +++ b/.github/workflows/bundler-integrations.yml @@ -38,4 +38,5 @@ jobs: - name: Check output working-directory: ./.github/workflows/bundler-integrations run: | - ! grep "Accordion" dist/${{matrix.bundler}}/*.js + ! grep "Accordion" dist/${{matrix.bundler}}/single-component.js -q + grep "Accordion" dist/${{matrix.bundler}}/initAll.js -q diff --git a/.github/workflows/bundler-integrations/index.html b/.github/workflows/bundler-integrations/index.html deleted file mode 100644 index a719560f0f..0000000000 --- a/.github/workflows/bundler-integrations/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Vite entry point - - - - - - diff --git a/.github/workflows/bundler-integrations/package.json b/.github/workflows/bundler-integrations/package.json index a3025c1803..b0a37901ec 100644 --- a/.github/workflows/bundler-integrations/package.json +++ b/.github/workflows/bundler-integrations/package.json @@ -3,8 +3,11 @@ "description": "Boilerplate to verify that GOV.UK Frontend works OK with main bundlers", "private": true, "scripts": { - "rollup": "rollup -c rollup.config.mjs src/index.mjs -o dist/rollup/main.js", - "webpack": "webpack ./src/index.mjs --mode production -o dist/webpack", + "rollup": "npm run rollup:single-component && npm run rollup:initAll", + "rollup:single-component": "npm run rollup:cli -- -o dist/rollup/single-component.js ./src/single-component.mjs", + "rollup:initAll": "npm run rollup:cli -- -o dist/rollup/initAll.js ./src/initAll.mjs", + "rollup:cli": "rollup -c rollup.config.mjs", + "webpack": "webpack --mode production -o dist/webpack", "vite": "vite build", "clean": "del-cli dist", "build:all": "concurrently \"npm run rollup\" \"npm run webpack\" \"npm run vite\" --names \"rollup,webpack,vite\" --prefix-colors \"red.dim,blue.dim,yellow.dim\"" diff --git a/.github/workflows/bundler-integrations/src/initAll.mjs b/.github/workflows/bundler-integrations/src/initAll.mjs new file mode 100644 index 0000000000..fed6187dd4 --- /dev/null +++ b/.github/workflows/bundler-integrations/src/initAll.mjs @@ -0,0 +1,4 @@ +// An example of importing and initialising allcomponents via initAll +import { initAll } from 'govuk-frontend' + +initAll() diff --git a/.github/workflows/bundler-integrations/src/index.mjs b/.github/workflows/bundler-integrations/src/single-component.mjs similarity index 71% rename from .github/workflows/bundler-integrations/src/index.mjs rename to .github/workflows/bundler-integrations/src/single-component.mjs index 9a45823853..cc535dff2e 100644 --- a/.github/workflows/bundler-integrations/src/index.mjs +++ b/.github/workflows/bundler-integrations/src/single-component.mjs @@ -1,3 +1,4 @@ +// An example of importing a single component from govuk-frontend and initialising it import { Button } from 'govuk-frontend' const $buttons = document.querySelectorAll('[data-module="govuk-button"]') diff --git a/.github/workflows/bundler-integrations/vite.config.mjs b/.github/workflows/bundler-integrations/vite.config.mjs index 65c7b4c9fa..a478ff6b86 100644 --- a/.github/workflows/bundler-integrations/vite.config.mjs +++ b/.github/workflows/bundler-integrations/vite.config.mjs @@ -1,10 +1,18 @@ /** @type {import('vite').UserConfig} */ +// the default vite config used by the different test case configs + export default { build: { // Align output with other bundlers to facilitate testing outDir: 'dist/vite', assetsDir: '.', // Prevent minification so we can see actual class/function names - minify: false + minify: false, + rollupOptions: { + input: ['./src/single-component.mjs', './src/initAll.mjs'], + output: { + entryFileNames: '[name].js' + } + } } } diff --git a/.github/workflows/bundler-integrations/webpack.config.js b/.github/workflows/bundler-integrations/webpack.config.js index 1919395560..cdb341cbd3 100644 --- a/.github/workflows/bundler-integrations/webpack.config.js +++ b/.github/workflows/bundler-integrations/webpack.config.js @@ -7,5 +7,12 @@ module.exports = { // Prevent minification so we can see what's going on in the built file minimize: false }, - target: 'web' + target: 'web', + entry: { + 'single-component': './src/single-component.mjs', + initAll: './src/initAll.mjs' + }, + output: { + filename: '[name].js' + } } diff --git a/docs/contributing/tasks.md b/docs/contributing/tasks.md index 50256e291a..988d545035 100644 --- a/docs/contributing/tasks.md +++ b/docs/contributing/tasks.md @@ -104,7 +104,7 @@ After building the project with `npm run build` the Express.js review app can be After building the project with `npm run build`, you can verify that the `govuk-frontend` package will be consumed correctly by mainstream bundlers with `npm run --workspace @govuk-frontend/bundler-integrations` (where bundler name is one of `rollup`, `webpack` or `vite`). -This will use the specified bundler to compile `.github/workflows/bundler-integrations/src/index.mjs`. That file only imports one components, which will let us verify that [tree shaking] works as intended. The build output (in `.github/workflows/bundler-integrations/dist//`) should not contain the code of other components. +This will use the specified bundler to compile both `.github/workflows/bundler-integrations/src/default.mjs` which is only importing one component, and `.github/workflows/bundler-integrations/src/initAll.mjs` which is importing and initialising all components via `initAll`. This helps us verify that [tree shaking] works as intended. The build output for both files is `.github/workflows/bundler-integrations/dist//[name].js`. `default.js` should not contain the code of other components whilst `initAll.js` should contain the code for all the components. You can also run `npm run build:all --workspace @govuk-frontend/bundler-integrations` to run all three bundlers in one go. From 9ed92a53fa99c7aac126e1369311747b9d72ceeb Mon Sep 17 00:00:00 2001 From: Owen Jones Date: Wed, 1 May 2024 11:43:10 +0100 Subject: [PATCH 10/10] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb8afbd5f0..88f86d757f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ For advice on how to use these release notes see [our guidance on staying up to We've made fixes to GOV.UK Frontend in the following pull requests: - [#4942: Remove duplicate `errorMessage` argument for the password input component](https://github.com/alphagov/govuk-frontend/pull/4942) - thanks to [Tim South](https://github.com/tim-s-ccs) for contributing this change +- [#4961: Fix tree-shaking when importing `govuk-frontend`](https://github.com/alphagov/govuk-frontend/pull/4961) ## 5.3.1 (Fix release)