Skip to content

Support Rollup's preserveModules #276

@slikts

Description

@slikts

Current Behavior

Currently a single bundle is output by rollup and module structure is not preserved.

Desired Behavior

There should be a way to do deep imports from the packaged library like so: import FooModule from "mylib/FooModule".

Suggested Solution

Rollup has a preserveModules option that includes the module structure in the built files.

A caveat is that the library should be published from the build directory to avoid having to include the build directory in the import path (like import FooModule from "mylib/dist/FooModule").

Who does this impact? Who is this for?

Here's a simple benchmark comparing deep vs bare imports from a large library: https://github.com/slikts/deep-vs-bare-import-bench

The performance impact of having to parse unused code is non-negligible for larger libraries, and it's compounding. Tree shaking only mitigates this for the final consumer but not while developing. Larger component libraries like MUI specifically support deep imports to avoid this problem.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions