Browse Source

fix CJS export

contingency-plan
Rich Harris 10 years ago
parent
commit
583552e9f2
  1. 3
      src/finalisers/umd.js
  2. 2
      test/form/export-default/_expected/umd.js

3
src/finalisers/umd.js

@ -26,11 +26,12 @@ export default function umd ( bundle, magicString, exportMode, options ) {
( has( options, 'moduleId' ) ? `['${options.moduleId}'], ` : `` ) +
( amdDeps.length ? `[${amdDeps.join( ', ' )}], ` : `` );
const cjsExport = exportMode === 'default' ? `module.exports = ` : ``;
const defaultExport = exportMode === 'default' ? `global.${options.moduleName} = ` : '';
const intro =
`(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(${cjsDeps.join( ', ' )}) :
typeof exports === 'object' && typeof module !== 'undefined' ? ${cjsExport}factory(${cjsDeps.join( ', ' )}) :
typeof define === 'function' && define.amd ? define(${amdParams}factory) :
${defaultExport}factory(${globalDeps});
}(this, function (${args}) { 'use strict';

2
test/form/export-default/_expected/umd.js

@ -1,5 +1,5 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
}(this, function () { 'use strict';

Loading…
Cancel
Save