Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack bundling changes #453

Merged
merged 7 commits into from
Dec 17, 2024
Merged

Webpack bundling changes #453

merged 7 commits into from
Dec 17, 2024

Conversation

ivansg44
Copy link
Collaborator

yarn build:web takes a while, and rebuilding the entire application isn't necessary if users are only editing schemas (as bundling the schemas takes much less time than bundling everything else).

I introduce yarn build:schemas, which only updates the schema content and is pretty quick.

How does this work?:

  • menu, getSchema, and getExportFormats are moved to schemas.js
  • index.js imports these as import ... from 'schemas'
  • We tell webpack.config.js that schemas is an external library
    • i.e., don't bundle schemas.js
  • The new webpack.schemas.js file bundles schemas.js instead, and outputs a locally available library
  • We import the path to this locally available schemas library inside index.html, which allows the original webpack.config.js build to reference this external schemas library without actually bundling it

Since the functions inside schemas.js are the only JavaScript that actually imports schema stuff (specifically schema.json and export.js files), any edits to schema stuff will not affect the webpack.config.js build. So if a user edits the schema content, they do not have to re-run the lengthy webpack.config.js build. Re-running webpack.schemas.js will suffice.

@ivansg44 ivansg44 added the wip Work in progress label Nov 25, 2024
@ivansg44
Copy link
Collaborator Author

I need to continue testing and make sure I didn't break anything

@ivansg44
Copy link
Collaborator Author

TODO edit README?

@ivansg44 ivansg44 requested a review from ddooley November 26, 2024 19:24
assetModuleFilename: 'assets/[hash][ext][query]',
},
externals: {
// Schemas lib external to this webpack build. Imported in html file.
Copy link
Collaborator Author

@ivansg44 ivansg44 Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit: import has to be in HTML

Add ref to webpack docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be in the header?

export const getSchema = async (schema) => {
return (await import(`./templates/${schema}/schema.json`)).default;
};
export const getExportFormats = async (schema) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getLocale?

@ivansg44
Copy link
Collaborator Author

I think the only change NML folks will need to worry about for their bundling logic is that menu, getSchema, and getExportForms in index.js are now imported from schemas.js. So another javascript file will be included in their bundle. I don't think they need to make any other changes, unless they also want to update their bundling logic to parallel ours (separate builds for application and schema content), but they don't have to do that.

@ddooley
Copy link
Collaborator

ddooley commented Dec 17, 2024

Looks great, I'm merging into master! And then Ken can merge into DH2-i18n-rc1 on his schedule. The Wastewater update will also have to be merged into master and into DH2-i18n-rc1, but I can do this as soon as Charlie ok's it.

@ddooley ddooley merged commit aa45f96 into master Dec 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wip Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants