Skip to content

Commit

Permalink
Amend bundle tests to also test against initAll importing
Browse files Browse the repository at this point in the history
This ensures that any changes we make to our importing process don't negatively impact users who're importing via `initAll`
  • Loading branch information
owenatgov committed May 2, 2024
1 parent 1f8c6ce commit 298c38d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/bundler-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}/default.js
grep "Accordion" dist/${{matrix.bundler}}/initAll.js
12 changes: 0 additions & 12 deletions .github/workflows/bundler-integrations/index.html

This file was deleted.

7 changes: 5 additions & 2 deletions .github/workflows/bundler-integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:default && npm run rollup:initAll",
"rollup:default": "npm run rollup:cli -- -o dist/rollup/default.js ./src/default.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\""
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/bundler-integrations/src/initAll.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { initAll } from 'govuk-frontend'

initAll()
10 changes: 9 additions & 1 deletion .github/workflows/bundler-integrations/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -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/default.mjs', './src/initAll.mjs'],
output: {
entryFileNames: '[name].js'
}
}
}
}
9 changes: 8 additions & 1 deletion .github/workflows/bundler-integrations/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
default: './src/default.mjs',
initAll: './src/initAll.mjs'
},
output: {
filename: '[name].js'
}
}
2 changes: 1 addition & 1 deletion docs/contributing/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <BUNDLER_NAME> --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/<BUNDLER_NAME>/`) 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/<BUNDLER_NAME>/[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.

Expand Down

0 comments on commit 298c38d

Please sign in to comment.