mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-09 14:45:00 -05:00
Make use of JS Modules less confusing
It's not obvious how the code that includes JS Modules in the frontend build works. This adds lots of comments to explain the various bits and flattens `modules/all.mjs` to just be a single function that starts off the window.GOVUK namespace. Also removes `module/all.js` from the repo'. It's an artefact used by the frontend build so shouldn't be included as source code.
This commit is contained in:
@@ -57,19 +57,24 @@ const bundleJavaScriptModules = async function () {
|
||||
const bundle = await rollup.rollup({
|
||||
input: paths.src + 'javascripts/modules/all.mjs',
|
||||
plugins: [
|
||||
// determine module entry points from either 'module' or 'main' fields in package.json
|
||||
rollupPluginNodeResolve({
|
||||
mainFields: ['module', 'main']
|
||||
}),
|
||||
// gulp rollup runs on nodeJS so reads modules in commonJS format
|
||||
// this adds node_modules to the require path so it can find the GOVUK Frontend modules
|
||||
rollupPluginCommonjs({
|
||||
include: 'node_modules/**'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
// write resulting module to Immediately Invoked Function Expression (IIFE) format
|
||||
// map the exported code to the window.GOVUK namespace
|
||||
await bundle.write({
|
||||
file: paths.src + 'javascripts/modules/all.js',
|
||||
format: 'iife',
|
||||
name: 'GOVUKFrontend'
|
||||
name: 'GOVUK'
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user