Skip to content

With format: iife, support exports as globals #3714

@edwinm

Description

@edwinm

Feature Use Case

I have a source file with an export:

export function a() {…}

I also have a rollup.config.js which has two outputs:

  output: [
    {
      file: "dist/bundle.min.js",
      format: "es",
      name: "bundle",
      sourcemap: true,
    },
    {
      file: "dist/bundle.iife.min.js",
      format: "iife",
      name: "b",
      sourcemap: true,
    },
  ],

Using the es version, I can use import {a} from 'bundle';, this works fine.

Using the iife version, I can only access a as b.a, which is undesirable.

Feature Proposal

I propose a solution to address this and make it possible to have a available as a global variable instead of a property of the bundle.

This feature has been requested in #494, but the (hacky) solution doesn't work anymore.

Possible solutions to indicate this in the config are:

  1. Just omit output.name.
  2. Set output.name to the empty string ""
  3. Set output.name to "window", similar to the solution in issue export to multiple globals without moduleName (IIFE)  #494.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions