text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _babelTemplate = require('babel-template');
  
  var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
  
  var _babelPluginSyntaxDynamicImport = require('babel-plugin-syntax-dynamic-import');
  
  var _babelPluginSyntaxDynamicImport2 = _interopRequireDefault(_babelPluginSyntaxDynamicImport);
  
  var _uuid = require('uuid');
  
  var _uuid2 = _interopRequireDefault(_uuid);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  var TYPE_IMPORT = 'Import'; // Based on https://github.com/airbnb/babel-plugin-dynamic-import-webpack
  // We've added support for SSR with this version
  
  
  var buildImport = function buildImport(args) {
    return (0, _babelTemplate2.default)('\n  (\n    typeof window === \'undefined\' ?\n      new (require(\'next/dynamic\').SameLoopPromise)((resolve, reject) => {\n        eval(\'require.ensure = function (deps, callback) { callback(require) }\')\n        require.ensure([], (require) => {\n          let m = require(SOURCE)\n          m.__webpackChunkName = \'' + args.name + '.js\'\n          resolve(m);\n        }, \'chunks/' + args.name + '.js\');\n      })\n      :\n      new (require(\'next/dynamic\').SameLoopPromise)((resolve, reject) => {\n        const weakId = require.resolveWeak(SOURCE)\n        try {\n          const weakModule = __webpack_require__(weakId)\n          return resolve(weakModule)\n        } catch (err) {}\n\n        require.ensure([], (require) => {\n          try {\n            let m = require(SOURCE)\n            resolve(m)\n          } catch(error) {\n            reject(error)\n          }\n        }, \'chunks/' + args.name + '.js\');\n      })\n  )\n');
  };
  
  exports.default = function () {
    return {
      inherits: _babelPluginSyntaxDynamicImport2.default,
  
      visitor: {
        CallExpression: function CallExpression(path) {
          if (path.node.callee.type === TYPE_IMPORT) {
            var moduleName = path.node.arguments[0].value;
            var name = moduleName.replace(/[^\w]/g, '-') + '-' + _uuid2.default.v4();
            var newImport = buildImport({
              name: name
            })({
              SOURCE: path.node.arguments
            });
            path.replaceWith(newImport);
          }
        }
      }
    };
  };