Skip to content

Commit

Permalink
Apply Babel transforms (without polyfills) on Rollup builds
Browse files Browse the repository at this point in the history
Transforms will be applied based on `.browserslistrc` supported browsers, with helper functions bundled if needed
  • Loading branch information
colinrotherham committed Jul 14, 2023
1 parent 35f6f6a commit d2c4e2e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions packages/govuk-frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Babel config
*
* @type {import('@babel/core').ConfigFunction}
*/
module.exports = function (api) {
const browserslistEnv = !api.env('test')
? 'javascripts'
: 'node'

return {
presets: [
['@babel/preset-env', {
browserslistEnv,
loose: browserslistEnv === 'javascripts',

// Transform ES modules for Node.js
modules: browserslistEnv === 'node' ? 'auto' : false
}]
]
}
}
3 changes: 3 additions & 0 deletions packages/govuk-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"dev": "gulp dev --color"
},
"devDependencies": {
"@babel/core": "^7.22.8",
"@babel/preset-env": "^7.22.7",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
"autoprefixer": "^10.4.14",
Expand Down
4 changes: 4 additions & 0 deletions packages/govuk-frontend/rollup.publish.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { babel } from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import { pkg } from 'govuk-frontend-config'
import { componentPathToModuleName } from 'govuk-frontend-lib/names'
Expand Down Expand Up @@ -61,6 +62,9 @@ export default defineConfig(({ i: input }) => ({

// Add GOV.UK Frontend release version
development: pkg.version
}),
babel({
babelHelpers: 'bundled'
})
]
}))
4 changes: 4 additions & 0 deletions packages/govuk-frontend/rollup.release.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { babel } from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import * as GOVUKFrontend from 'govuk-frontend/src/govuk/all.mjs'
Expand Down Expand Up @@ -53,6 +54,9 @@ export default defineConfig(({ i: input }) => ({

// Add GOV.UK Frontend release version
development: pkg.version
}),
babel({
babelHelpers: 'bundled'
})
]
}))
1 change: 1 addition & 0 deletions packages/govuk-frontend/tasks/build/package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('packages/govuk-frontend/dist/', () => {
// Check top level package contents
expect(listingPackage).toEqual([
'README.md',
'babel.config.js',
'govuk-prototype-kit.config.json',
'gulpfile.mjs',
'package.json',
Expand Down

0 comments on commit d2c4e2e

Please sign in to comment.