|
@ -1,3 +1,4 @@ |
|
|
|
|
|
import getInteropBlock from './shared/getInteropBlock'; |
|
|
import getExportBlock from './shared/getExportBlock'; |
|
|
import getExportBlock from './shared/getExportBlock'; |
|
|
|
|
|
|
|
|
export default function cjs ( bundle, magicString, { exportMode }, options ) { |
|
|
export default function cjs ( bundle, magicString, { exportMode }, options ) { |
|
@ -5,16 +6,8 @@ export default function cjs ( bundle, magicString, { exportMode }, options ) { |
|
|
|
|
|
|
|
|
// TODO handle empty imports, once they're supported
|
|
|
// TODO handle empty imports, once they're supported
|
|
|
const importBlock = bundle.externalModules |
|
|
const importBlock = bundle.externalModules |
|
|
.map( module => { |
|
|
.map( module => `var ${module.name} = require('${module.id}');`) |
|
|
let requireStatement = `var ${module.name} = require('${module.id}');`; |
|
|
.concat( getInteropBlock( bundle ) ) |
|
|
|
|
|
|
|
|
if ( module.needsDefault ) { |
|
|
|
|
|
requireStatement += '\n' + ( module.needsNamed ? `var ${module.name}__default = ` : `${module.name} = ` ) + |
|
|
|
|
|
`'default' in ${module.name} ? ${module.name}['default'] : ${module.name};`; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return requireStatement; |
|
|
|
|
|
}) |
|
|
|
|
|
.join( '\n' ); |
|
|
.join( '\n' ); |
|
|
|
|
|
|
|
|
if ( importBlock ) { |
|
|
if ( importBlock ) { |
|
|