From a6c821fd3daab62b5d28b5e5ce33a0bfab9a5989 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Wed, 31 May 2023 19:50:49 +0100 Subject: [PATCH] Enable Rollup dual compile for ES and CommonJS modules All modules are now compiled to `dist/govuk` with UMD bundles removed for now (e.g. `all.js` is now a CommonJS module) --- docs/contributing/tasks.md | 4 +- .../govuk-frontend-review/tasks/scripts.mjs | 2 +- .../govuk-frontend-review/tasks/watch.mjs | 4 +- packages/govuk-frontend/package.json | 4 +- ...m.config.mjs => rollup.modules.config.mjs} | 24 ++-- packages/govuk-frontend/rollup.umd.config.mjs | 39 ------- .../tasks/build/package.test.mjs | 106 +++++++++++------- .../govuk-frontend/tasks/build/release.mjs | 2 +- packages/govuk-frontend/tasks/scripts.mjs | 19 +--- 9 files changed, 93 insertions(+), 111 deletions(-) rename packages/govuk-frontend/{rollup.esm.config.mjs => rollup.modules.config.mjs} (55%) delete mode 100644 packages/govuk-frontend/rollup.umd.config.mjs diff --git a/docs/contributing/tasks.md b/docs/contributing/tasks.md index e44b6b236f..283f1cf7ad 100644 --- a/docs/contributing/tasks.md +++ b/docs/contributing/tasks.md @@ -39,8 +39,8 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks. - copy Sass files, applying Autoprefixer via PostCSS - copy Nunjucks component template/macro files, including JSON configs - copy GOV.UK Prototype Kit config files +- compile JavaScript to CommonJS modules - compile JavaScript to ECMAScript (ES) modules -- compile JavaScript to Universal Module Definition (UMD) - runs `npm run postbuild:package` (which will test the output is correct) **`npm run build:release` will do the following:** @@ -91,7 +91,7 @@ This task will: This task will: - check JavaScript code quality via ESLint (`npm run lint:js`) (using JavaScript Standard Style) -- compile JavaScript to Universal Module Definition (UMD) into `./packages/govuk-frontend-review/dist/javascripts` +- compile JavaScript to Immediately Invoked Function Expression (IIFE) into `./packages/govuk-frontend-review/dist/javascripts` - compile JavaScript documentation into `./packages/govuk-frontend-review/dist/docs/jsdoc` ## Review app only diff --git a/packages/govuk-frontend-review/tasks/scripts.mjs b/packages/govuk-frontend-review/tasks/scripts.mjs index 9ec4badaf0..975b20475e 100644 --- a/packages/govuk-frontend-review/tasks/scripts.mjs +++ b/packages/govuk-frontend-review/tasks/scripts.mjs @@ -10,7 +10,7 @@ import gulp from 'gulp' * @type {import('govuk-frontend-tasks').TaskFunction} */ export const compile = (options) => gulp.series( - task.name('compile:js', () => + task.name("compile:js 'bundle'", () => scripts.compile('all.mjs', { ...options, diff --git a/packages/govuk-frontend-review/tasks/watch.mjs b/packages/govuk-frontend-review/tasks/watch.mjs index 59c3d60200..c27bec851c 100644 --- a/packages/govuk-frontend-review/tasks/watch.mjs +++ b/packages/govuk-frontend-review/tasks/watch.mjs @@ -48,11 +48,11 @@ export const watch = (options) => gulp.parallel( /** * JavaScripts build watcher */ - task.name('compile:js watch', () => + task.name("compile:js 'bundle' watch", () => gulp.watch([ `${slash(paths.root)}/typedoc.config.js`, `${slash(paths.app)}/src/javascripts/**/*.mjs`, - `${slash(paths.package)}/dist/govuk-esm/**/*.mjs` + `${slash(paths.package)}/dist/govuk/**/*.mjs` ], scripts(options)) ) ) diff --git a/packages/govuk-frontend/package.json b/packages/govuk-frontend/package.json index 1b06581e6f..996066a521 100644 --- a/packages/govuk-frontend/package.json +++ b/packages/govuk-frontend/package.json @@ -3,7 +3,7 @@ "description": "GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.", "version": "4.6.0", "main": "dist/govuk/all.js", - "module": "dist/govuk-esm/all.mjs", + "module": "dist/govuk/all.mjs", "files": [ "dist", "govuk-prototype-kit.config.json", @@ -13,7 +13,7 @@ "exports": { ".": { "sass": "./dist/govuk/all.scss", - "import": "./dist/govuk-esm/all.mjs", + "import": "./dist/govuk/all.mjs", "require": "./dist/govuk/all.js" }, "./*": "./*" diff --git a/packages/govuk-frontend/rollup.esm.config.mjs b/packages/govuk-frontend/rollup.modules.config.mjs similarity index 55% rename from packages/govuk-frontend/rollup.esm.config.mjs rename to packages/govuk-frontend/rollup.modules.config.mjs index 7b45977d96..18bf9429a3 100644 --- a/packages/govuk-frontend/rollup.esm.config.mjs +++ b/packages/govuk-frontend/rollup.modules.config.mjs @@ -5,8 +5,10 @@ import { defineConfig } from 'rollup' /** * Rollup config for npm publish * - * ECMAScript (ES) modules for browser