index.js
function transform(str) {
  str = str.split(/^lazy\(/gm).join('require(');
  var lines = str.split(/\r\n|\n/);
  var len = lines.length;
  var re = regex();
  var idx = 0;

  var start = false;
  var isExported = false;
  var namespace;
  var res = '';

  while (idx < len) {
    var line = lines[idx++];
    res += '\n';

    if (/(?:var fn = require|require = utils)/.test(line)) {
      continue;
    }
    if (/^require = fn/.test(line)) {
      continue;
    }
    // adding this line to catch other variable names than the more specific cases above
    if (/^require = (?:.*)/.test(line)) {
      continue;
    }

    var match = re.exec(line);
    if (!match) {
      res += line;
      continue;
    }

    if (match && (match[2] === 'lazy-cache' || match[3] === 'lazy-cache')) {
      namespace = toNamespace(match[1]);
      if (/module\.exports/.test(match[1])) {
        isExported = true;
      }
      line = 'var ' + namespace + ' = {};';
      start = true;
      res += line;
      continue;
    }

    if (!start) {
      res += line;
      continue;
    }

    var variable = toVariable(match);
    var prefix = toProperty(namespace, variable, match[2]);
    line = line.split(match[0]).join(prefix);
    res += line;
  }

  if (isExported) {
    res += '\nmodule.exports = ' + namespace + ';';
  }
  return res.replace(/^\s+/, '');
}
function transform(str) {
  str = str.split(/^lazy\(/gm).join('require(');
  var lines = str.split(/\r\n|\n/);
  var len = lines.length;
  var re = regex();
  var idx = 0;

  var start = false;
  var isExported = false;
  var namespace;
  var res = '';

  while (idx < len) {
    var line = lines[idx++];
    res += '\n';

    if (/(?:var fn = require|require = utils)/.test(line)) {
      continue;
    }
    if (/^require = fn/.test(line)) {
      continue;
    }
    // adding this line to catch other variable names than the more specific cases above
    if (/^require = (?:.*)/.test(line)) {
      continue;
    }

    var match = re.exec(line);
    if (!match) {
      res += line;
      continue;
    }

    if (match && (match[2] === 'lazy-cache' || match[3] === 'lazy-cache')) {
      namespace = toNamespace(match[1]);
      if (/module\.exports/.test(match[1])) {
        isExported = true;
      }
      line = 'var ' + namespace + ' = {};';
      start = true;
      res += line;
      continue;
    }

    if (!start) {
      res += line;
      continue;
    }

    var variable = toVariable(match);
    var prefix = toProperty(namespace, variable, match[2]);
    line = line.split(match[0]).join(prefix);
    res += line;
  }

  if (isExported) {
    res += '\nmodule.exports = ' + namespace + ';';
  }
  return res.replace(/^\s+/, '');
}
function transform ( str ) { str = str . split ( / ^lazy\( / gm ) . join ( 'require(' ) ; var lines = str . split ( / \r\n|\n / ) ; var len = lines . length ; var re = regex ( ) ; var idx = 0 ; var start = false ; var isExported = false ; var namespace ; var res = '' ; while ( idx < len ) { var line = lines [ idx ++ ] ; res += '\n' ; if ( / (?:var fn = require|require = utils) / . test ( line ) ) { continue ; } if ( / ^require = fn / . test ( line ) ) { continue ; } // adding this line to catch other variable names than the more specific cases above if ( / ^require = (?:.*) / . test ( line ) ) { continue ; } var match = re . exec ( line ) ; if ( ! match ) { res += line ; continue ; } if ( match && ( match [ 2 ] === 'lazy-cache' || match [ 3 ] === 'lazy-cache' ) ) { namespace = toNamespace ( match [ 1 ] ) ; if ( / module\.exports / . test ( match [ 1 ] ) ) { isExported = true ; } line = 'var ' + namespace + ' = {};' ; start = true ; res += line ; continue ; } if ( ! start ) { res += line ; continue ; } var variable = toVariable ( match ) ; var prefix = toProperty ( namespace , variable , match [ 2 ] ) ; line = line . split ( match [ 0 ] ) . join ( prefix ) ; res += line ; } if ( isExported ) { res += '\nmodule.exports = ' + namespace + ';' ; } return res . replace ( / ^\s+ / , '' ) ; }
Transform source code containing lazy-cache statements into a requirable file usable with webpack.

@param  {String} `source` Source code.
@return {String} Transformed source code.
Transform source code containing lazy - cache statements into a requirable file usable with webpack .