|
@ -1,6 +1,7 @@ |
|
|
import { blank } from '../utils/object'; |
|
|
import { blank } from '../utils/object'; |
|
|
import { getName } from '../utils/map-helpers'; |
|
|
import { getName } from '../utils/map-helpers'; |
|
|
import getInteropBlock from './shared/getInteropBlock'; |
|
|
import getInteropBlock from './shared/getInteropBlock'; |
|
|
|
|
|
import getExportBlock from './shared/getExportBlock'; |
|
|
|
|
|
|
|
|
export default function iife ( bundle, magicString, { exportMode, indentString }, options ) { |
|
|
export default function iife ( bundle, magicString, { exportMode, indentString }, options ) { |
|
|
const globalNames = options.globals || blank(); |
|
|
const globalNames = options.globals || blank(); |
|
@ -23,16 +24,16 @@ export default function iife ( bundle, magicString, { exportMode, indentString } |
|
|
let intro = `(function (${args}) { 'use strict';\n\n`; |
|
|
let intro = `(function (${args}) { 'use strict';\n\n`; |
|
|
let outro = `\n\n})(${dependencies});`; |
|
|
let outro = `\n\n})(${dependencies});`; |
|
|
|
|
|
|
|
|
// var foo__default = 'default' in foo ? foo['default'] : foo;
|
|
|
|
|
|
const interopBlock = getInteropBlock( bundle ); |
|
|
|
|
|
if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' ); |
|
|
|
|
|
|
|
|
|
|
|
if ( exportMode === 'default' ) { |
|
|
if ( exportMode === 'default' ) { |
|
|
intro = `var ${options.moduleName} = ${intro}`; |
|
|
intro = `var ${options.moduleName} = ${intro}`; |
|
|
magicString.append( `\n\nreturn ${bundle.entryModule.getCanonicalName('default')};` ); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO named exports
|
|
|
// var foo__default = 'default' in foo ? foo['default'] : foo;
|
|
|
|
|
|
const interopBlock = getInteropBlock( bundle ); |
|
|
|
|
|
if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' ); |
|
|
|
|
|
|
|
|
|
|
|
const exportBlock = getExportBlock( bundle, exportMode ); |
|
|
|
|
|
if ( exportBlock ) magicString.append( '\n\n' + exportBlock ); |
|
|
|
|
|
|
|
|
return magicString |
|
|
return magicString |
|
|
.indent( indentString ) |
|
|
.indent( indentString ) |
|
|