Skip to content

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ScriptedAlchemy
Copy link
Member

@ScriptedAlchemy ScriptedAlchemy commented Apr 16, 2025

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:

    • Introduced definePluginOptions to manage DefinePlugin settings.
    • Added FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN to handle disabling snapshot optimizations.
    • Implemented environment target detection (web or node) based on compiler options and experiments.
    • Consolidated DefinePlugin application with the newly constructed definePluginOptions.
  • Environment-Specific Handling:

    • Declared ENV_TARGET constant to differentiate between 'web' and 'node' environments.
    • Modified createScriptNode and loadScriptNode to execute only in Node.js environment, throwing an error if attempted in a non-Node.js environment. [1] [2] [3]
    • Added logging for debugging purposes.
  • Build Optimization Options:

    • Introduced optimization options in ModuleFederationPluginOptions, including configurations for disableSnapshot and target environment optimizations. [1] [2] [3]
    • Added conditional functionality for snapshots and optimized entry loading.
  • Documentation Updates:

    • Updated documentation to include new optimization options and their impacts.
  • Code Refactoring:

    • Extracted duplicated logic for handling remote entry loaded into handleRemoteEntryLoaded function. [1] [2] [3] [4]
    • Simplified plugin loading logic to check 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

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Copy link

netlify bot commented Apr 16, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 1ff85e9
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/68005678adbd4a000885070a
😎 Deploy Preview https://deploy-preview-3704--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ScriptedAlchemy
Copy link
Member Author

Main (Current)

remoteEntry.js size: 70K
gzip size: 21732 bytes
brotli size: 19229 bytes

This Branch (no optimization flag enabled)

remoteEntry.js size: 69K
gzip size: 21437 bytes
brotli size: 19024 bytes

disableSnapshot: true

remoteEntry.js size: 65K
gzip size: 20096 bytes
brotli size: 17860 bytes

target: 'web'

remoteEntry.js size: 60K
gzip size: 19314 bytes
brotli size: 17105 bytes

Both enabled

remoteEntry.js size: 56K
gzip size: 17998 bytes
brotli size: 15982 bytes

Both enabled + external runtime enabled

remoteEntry.js size: 14K
gzip size: 5381 bytes
brotli size: 4703 bytes

Both disabled + external runtime enabled

remoteEntry.js size: 22K
gzip size: 8222 bytes
brotli size: 7269 bytes

@ScriptedAlchemy ScriptedAlchemy marked this pull request as ready for review April 16, 2025 17:55
…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.
Copy link

@Copilot Copilot AI left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant