-
-
Notifications
You must be signed in to change notification settings - Fork 357
perf: add tree shake markers to enable/disable capabilities to reduce bundle size #3704
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
Conversation
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Main (Current)
This Branch (no optimization flag enabled)
disableSnapshot: true
target: 'web'
Both enabled
Both enabled + external runtime enabled
Both disabled + external runtime enabled
|
…/tree-shake-flags
…ion parity Adds FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN and ENV_TARGET support. Enables new optimization and environment targeting options. Ensures parity with webpack plugin. Enables runtime feature toggling. Enables tree-shaking in runtime and SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 10 out of 13 changed files in this pull request and generated no comments.
Files not reviewed (3)
- apps/website-new/docs/en/configure/experiments.mdx: Language not supported
- package.json: Language not supported
- packages/chrome-devtools/project.json: Language not supported
# Conflicts: # package.json
…N when explicitly set
provideExternalRuntime: false | ||
provideExternalRuntime: false, | ||
optimization: { | ||
disableSnapshot: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks better to change it to "disable manifest"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also includes the inability to use the ts type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but there are many users who come from webpack v1 - they want direct switch to v2 and dont use any new capability - first introduction to v2 is a v70kb increase in entry file - and many companies took advantage of small remote entry size of v1 where its like 10kb, they will load 80+ remote modules, but now they are 7X larger and remoteEntry becomes 5.7mb of eager chunk loading required to initialize the system. So these users would prefer to turn off features they do not yet adopt, then explore wha they need and slowly increase the payload size while communicating the values of the additional runtime code. Or if user is in production - they may want no json http call and prefer js entry with minimal payload overhead, so they can use lite
federaiton in prod and full
in lower environment if they needed to balance the overhead at the expense of capabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any user not using json protocol has no ts sync already. So if user only uses js remote they already are on ~v1.5 level capabilities. So they have no requirement for the code and already do not leverage all of v2 features. Some user wants v1 + runtime plugin. to keep payload cost of adoption small but valuable to busniess case.
provideExternalRuntime: false, | ||
optimization: { | ||
disableSnapshot: false, | ||
target: 'web', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this designed for other bundler like vite ? Becasue we can infer it from automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, will it automatically be apply in webpack/rspack ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not designed for other bundler - but i was worried about automatic inference because case like web worker or custom react native target, the infer target may not always be accurate - and you end up removing part of the system from a environment acting like another. Like in react native or lynx - it use commonjs chunk loader - but may be target of web worker or worker, so this may compile to web target but use other mechanics and assuming that may have breaking implications. Yes we can detect, but custom environment or mixed output could exist that i dont foresee right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the feature will work in webpack and rspack, but currently user must opt into it explicitly - so if there is problem, they understand why because they enabled it. We could add a 'auto' option where we add attempt to infer, so user still must use flag to enable and we can add other enums to it if needed like react-native for custom env target code that we may need to support within the runtime core - without making the core larger - and if user want to tree shake the vanillia runtime themselves - they can just set these in define
plugins of their own bundler and customize the library for their own needs as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha cool
|
||
Updated ModuleFederationPlugin to enhance configuration capabilities and target environment identification. | ||
|
||
- Introduced `definePluginOptions` to manage DefinePlugin settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format changeset can not be consumed . need to fix https://github.com/module-federation/core/actions/runs/15035515868/job/42256409157
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed there was ``` in another file that broke it
🦋 Changeset detectedLatest commit: e45311b The changes in this PR will be included in the next version bump. This PR includes changesets to release 32 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Description
This pull request introduces several enhancements and optimizations to the Module Federation Plugin and related packages. The main changes focus on improving configuration capabilities, optimizing build processes, and adding environment-specific handling for certain functions.
Enhancements and Optimizations:
Module Federation Plugin Enhancements:
definePluginOptions
to manageDefinePlugin
settings.FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
to handle disabling snapshot optimizations.web
ornode
) based on compiler options and experiments.DefinePlugin
application with the newly constructeddefinePluginOptions
.Environment-Specific Handling:
ENV_TARGET
constant to differentiate between 'web' and 'node' environments.createScriptNode
andloadScriptNode
to execute only in Node.js environment, throwing an error if attempted in a non-Node.js environment. [1] [2] [3]Build Optimization Options:
optimization
options inModuleFederationPluginOptions
, including configurations fordisableSnapshot
andtarget
environment optimizations. [1] [2] [3]Documentation Updates:
Code Refactoring:
handleRemoteEntryLoaded
function. [1] [2] [3] [4]USE_SNAPSHOT
flag. [1] [2] [3]These changes aim to enhance the flexibility and performance of the Module Federation Plugin by providing more granular control over build optimizations and environment-specific behavior.
Related Issue
Types of changes
Checklist