Open
Conversation
- Introduce `FrontendResource` to represent a resource that will be bundled. This is a change from the previous method of defining everything as just a path. This allows more flexibility in how resources are handled. For example, we can now represent usage of an ES Module as a path and the used exports from that module, which enables the bundler to produce a smaller build. It also means we can more easily filter resources based on the resource class, whereas before the only thing you can filter on was the path (e.g. guess the type from the extension). - Rename FrontendAssetRegistry to FrontendResourceRegistry and change it to support adding resources, not just paths (paths are still supported for convenience). - Intrduce extract_frontend_resources that will export the used resources in a new format containing all the details necessary for the bundler to make use of the extra info. - extract_frontend_assets still works, but is deprecated
Fix cases where an asset may be treated as undiscoverable incorrectly. This occurs when
using a component as a var, e.g. {% component "package" "MyComponent" as my_var %}{% endcomponent %}
and then passing that as a prop to another component. When the prop is processed in the
component it is passed to it would previously throw an error about it being undiscoverable.
This fix accumulates the known resources as we go, so if the prop is encountered after the
node has been processed it is no longer considered unknown.
This would not have previously caused issues if the prop passed used an import path that was
used in the component (e.g. @alliancesoftware/ui components). With the new changes, this
would be much more common as using a new import from that package would be treated as a
unique usage.
81c1841 to
5a80d26
Compare
Allow a full JavascriptResource to cover off on specific imports from that resource This makes it so adding a path to a file is sufficient to cover off on any imports used from that file.
micahklaz
requested changes
Dec 9, 2024
Collaborator
micahklaz
left a comment
There was a problem hiding this comment.
A few typos and doc fixes to address
packages/ap-frontend/alliance_platform/frontend/bundler/context.py
Outdated
Show resolved
Hide resolved
packages/ap-frontend/alliance_platform/frontend/bundler/base.py
Outdated
Show resolved
Hide resolved
packages/ap-frontend/alliance_platform/frontend/bundler/context.py
Outdated
Show resolved
Hide resolved
packages/ap-frontend/alliance_platform/frontend/bundler/vite.py
Outdated
Show resolved
Hide resolved
micahklaz
approved these changes
Jan 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AP114: Bundle Size Optimisations
This PR introduces significant improvements to how frontend resources are managed, providing greater flexibility
in bundling. With these changes, the default bundle size in the template size is ~75% smaller.
Key Changes:
I've tested the package in an existing project with no changes to use new interfaces, and it will work but with deprecation warnings.
I will be introducing another MR to the template, and possibly a new @alliancesoftware/ JS package, to handle the build side of this (i.e. the Vite plugin that makes use of the output of
extract_frontend_resources). I'll also add a doc page for upgrading once that's done.