Skip to content

Commit

Permalink
Build GitHub release JavaScript also into package
Browse files Browse the repository at this point in the history
This runs the Rollup build for our GitHub release JavaScript `govuk-frontend-{{ version }}.min.js` into package too but without the version number
  • Loading branch information
colinrotherham committed Jul 5, 2023
1 parent 7c02825 commit f9079c6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/govuk-frontend/tasks/build/package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ describe('packages/govuk-frontend/dist/', () => {
join(requirePath, `${name}.bundle.mjs.map`) // with source map
]))

// Only main package entry is compiled to minified ES module bundle
.flatMap(mapPathTo(['**/govuk/all.mjs'], ({ dir: requirePath }) => [
join(requirePath, 'all.mjs'),

// ES module bundles for browsers, minified
join(requirePath, 'govuk-frontend.min.js'), // avoid .mjs extension MIME issues
join(requirePath, 'govuk-frontend.min.js.map') // with source map
]))

// Add Autoprefixer prefixes to all source '*.scss' files
.flatMap(mapPathTo(['**/*.scss'], ({ dir: requirePath, name }) => [
join(requirePath, `${name}.scss`),
Expand Down
20 changes: 20 additions & 0 deletions packages/govuk-frontend/tasks/scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join, resolve } from 'path'

import { pkg } from 'govuk-frontend-config'
import { configs, scripts, npm, task } from 'govuk-frontend-tasks'
import gulp from 'gulp'

Expand All @@ -22,6 +23,25 @@ export const compile = (options) => gulp.series(
})
),

/**
* Compile GOV.UK Frontend JavaScript (minified) for main entry point only
*/
task.name("compile:js 'minified'", () =>
scripts.compile('**/all.mjs', {
...options,

srcPath: join(options.srcPath, 'govuk'),
destPath: join(options.destPath, 'govuk'),
configPath: join(options.basePath, 'rollup.release.config.mjs'),

// Rename using package name and `*.min.js` extension due to
// web server ES module `*.mjs` Content-Type header support
filePath ({ dir, name }) {
return join(dir, `${name.replace(/^all/, pkg.name)}.min.js`)
}
})
),

/**
* Compile GOV.UK Prototype Kit config
*/
Expand Down

0 comments on commit f9079c6

Please sign in to comment.