Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

output iife without name #274

@zanona

Description

@zanona

Case A

rollup a-import.js -c --output.format iife --output.name myBundle

a-import.js

import b from './b';
console.log(b.foo);

result 👌 this is what I would expect

(function () {
'use strict';
var b = { foo: 'bar' };
console.log(b.foo);
}());

However, when using a-require.js instead, where require is used instead of import the result is:

Case B

rollup a-require.js -c --output.format iife --output.name myBundle

a-require.js

const b = require('./b');
console.log(b.foo);

result 😕 not quite what I expect

var myBundle = (function () { //<-- why do I need a named export?
'use strict';
var b = { foo: 'bar' };
console.log(b.foo);
var a = {}; // <-- why is it creating a module out of the entry file since nothing is being exported?
return a;
}());

How can I get the same output of case A when using commonjs require instead?

  • Just highlighting that --output.name is necessary on case B otherwise the command will fail with [!] Error: You must supply options.name for IIFE bundles

For reference, here are the involved files

rollup.config.js

import commonjs from 'rollup-plugin-commonjs';
export default { plugins: [commonjs()] };

b.js

module.exports = { foo: 'bar' };

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