Skip to content

Commit

Permalink
Remove the need to provide an output name for IIFE bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
bterrier committed Oct 25, 2019
1 parent b0d35e1 commit 9a1d5c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/finalisers/iife.ts
Expand Up @@ -48,9 +48,8 @@ export default function iife(
const args = external.map(m => m.name);

if (hasExports && !name) {
error({
code: 'INVALID_OPTION',
message: `You must supply "output.name" for IIFE bundles.`
warn({
message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`
});
}

Expand All @@ -68,9 +67,9 @@ export default function iife(

let wrapperIntro = `(function${_}(${args.join(`,${_}`)})${_}{${n}${useStrict}`;

if (hasExports && (!extend || !namedExportsMode)) {
if (hasExports && (!extend || !namedExportsMode) && name) {
wrapperIntro =
(useVariableAssignment ? `${varOrConst} ${name}` : thisProp(name as string)) +
(useVariableAssignment ? `${varOrConst} ${name}` : thisProp(name)) +
`${_}=${_}${wrapperIntro}`;
}

Expand Down
12 changes: 1 addition & 11 deletions test/misc/write-bundle.js
Expand Up @@ -25,7 +25,7 @@ describe('bundle.write()', () => {
});
});

it('expects output.name for IIFE and UMD bundles', () => {
it('expects output.name for UMD bundles', () => {
let bundle;

return rollup
Expand All @@ -48,16 +48,6 @@ describe('bundle.write()', () => {
assert.throws(() => {
throw err;
}, /You must supply "output\.name" for UMD bundles/);
})
.then(() => {
return bundle.generate({
format: 'iife'
});
})
.catch(err => {
assert.throws(() => {
throw err;
}, /You must supply "output\.name" for IIFE bundles/);
});
});

Expand Down

0 comments on commit 9a1d5c1

Please sign in to comment.