Skip to content

Support output.globals for other formats #2374

@eight04

Description

@eight04

Related: #1665

Currently, output.globals is only used if format is iife or umd. If format is es and we want to map the external module to a global variable, we usually solve it with a shim/alias plugin (e.g. export default $). However, this solution doesn't work well with experimentalCodeSplitting. When code splitting is enabled, the shim module would be chunked instead of being inlined:
entry.js

import $ from "./chunk-xxx.js";
...

entry2.js

import $ from "./chunk-xxx.js";
...

chunk-xxx.js

export default $;

By enabling output.globals for other formats, we can avoid sharing the shim module.

Another solution is to enable code splitting for iife when there is no shared dependency (or marking all shared dependencies as externals). Related: #2072

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions