Skip to content

Avoid runtime imports of typescript if DtsPlugin is not configured #4271

@MichaelWashburnJr

Description

@MichaelWashburnJr

Clear and concise description of the problem

👋 I'd like to update some of the places where DtsPlugin gets imported so that it is only required when needed.

I'm working on a project that prunes typescript out of the node_modules folder because it is not in use (but still installed due to a dep on scip-typescript). Typescript increased the footprint of our project by 32MB when it wasn't being pruned, hence why we delete it.

Suggested solution

I've done local testing and for an Rspack usage, I only need to adjust imports to DtsPlugin in these two files:

  • packages/manifest/src/utils.ts
  • packages/rspack/src/ModuleFederationPlugin.ts

In these files I would remove top of file imports from require('@module-federation/dts-plugin'); (and dts-plugin/core) and replace them by requiring the module after we check that dts is configured.

Doing this makes it so that typescript itself is no longer imported during runtime if dts is disabled in your module federation config.

Alternative

A cleaner API would be to move to a composition pattern where users pass in pre-configured plugins for MF to use, but that wouldn't be a simple backwards-compatible change.

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions