Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Support CommonJS modules transpiled by Babel #10

Closed
Victorystick opened this issue Nov 23, 2015 · 1 comment
Closed

Support CommonJS modules transpiled by Babel #10

Victorystick opened this issue Nov 23, 2015 · 1 comment

Comments

@Victorystick
Copy link
Contributor

The CommonJS plugin doesn't handle ES6 transpile-style exports very well. I present two examples why support must be improved:

Because this isn't very nice

// source
export default function () { return 1337; }
// after babel
"use strict";

exports.__esModule = true;

exports["default"] = function () {
  return 1337;
};

module.exports = exports["default"];
// after rollup-plugin-commonjs
var leet = (function (module) {
  var exports = module.exports;
  "use strict";

  exports.__esModule = true;

  exports["default"] = function () {
    return 1337;
  };

  module.exports = exports["default"];
  return module.exports;
})({exports:{}});

var __esModule = leet.__esModule;

export { __esModule };export default leet;

That's quite a bit of bloat.

Worse: code like this breaks

// `babel-runtime/core-js/get-iterator.js` source
module.exports = { "default": require("core-js/library/fn/get-iterator"), __esModule: true };

We do not give exports['default'] special treatment.

// after rollup-plugin-commonjs
import require$$0 from 'core-js/library/fn/get-iterator';

var getIterator = (function (module) {
var exports = module.exports;
module.exports = { "default": require$$0, __esModule: true };
return module.exports; // an object is exported, not a function
})({exports:{}});

export default getIterator;
@tdeekens
Copy link

@Victorystick sorry to bring back old memories but was this solved for you? I have trouble when the plugin seems to run over core-js code which then ends up in babel. This code seems to break my build

import '../../modules/es6.string.iterator';
import '../../modules/es6.array.from';
import '../../modules/_core';
import 'commonjs-proxy:../../modules/es6.string.iterator';
import 'commonjs-proxy:../../modules/es6.array.from';
import require$$2 from 'commonjs-proxy:../../modules/_core';

Any idea as of why or how to fix it? Help would be really greatly appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants