Skip to content

[Feature]: Support custom module identifiers (ids) #10764

@dinofx

Description

@dinofx

What problem does this feature solve?

In Webpack we were able to hook the compilation's beforeModuleIds hook and use our own method for generating the module ids and assigning them to each module. We do this because an import to a module like "foo/bar" resolves (using our own custom resolution strategy) to a path that includes the exact version of the package "foo". So the path to a module can change between builds, even if its source hasn't.

The default/current behavior for generating module ids in Rspack includes these unstable paths. Since the module identifier changes between builds, several other things seem affected. "deterministic" chunk ids are changing, even when the entire source content of the chunk is unchanged (other than the string containing its id at the beginning, and source map URL at the end).

As a result, all of our assets are cache-busted between builds. Our apps have minimal CSS that rarely changes, and code splits for packages like React. With webpack these assets are often cacheable from previous builds of an app.

What does the proposed API of configuration look like?

One option is to support the beforeModuleIds AND allow the relevant Module properties that are updated by the hook to be copied back to the Rust data structures.

But, it might make more sense to use an explicit output setting. Maybe a function similar to devtoolModuleFilenameTemplate and devtoolFallbackModuleFilenameTemplate, but for module ids.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions