From f81085ad9a495e8917025386ad3b5605b42b7dab Mon Sep 17 00:00:00 2001 From: Benjamin Terrier Date: Mon, 21 Oct 2019 13:48:49 +0200 Subject: [PATCH] Remove the need to provide an output name for IIFE bundles --- src/finalisers/iife.ts | 9 ++++----- test/misc/write-bundle.js | 12 +----------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/finalisers/iife.ts b/src/finalisers/iife.ts index 755748e169b..a87a4b535c1 100644 --- a/src/finalisers/iife.ts +++ b/src/finalisers/iife.ts @@ -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.` }); } @@ -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}`; } diff --git a/test/misc/write-bundle.js b/test/misc/write-bundle.js index decb030012e..8caacb5f679 100644 --- a/test/misc/write-bundle.js +++ b/test/misc/write-bundle.js @@ -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 @@ -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/); }); });