-
Notifications
You must be signed in to change notification settings - Fork 116
Use named exports as a function when no default export is defined #44
Conversation
It looks good to me. It adds a bit of complexity, but I've encountered scenarios where this is absolutely necessary if Rollup is to bundle the code. 👍 cc @rollup/collaborators In time, we may want to refactor the |
@Victorystick LGTM. I'd like to release this feature, caz I can't build bundle with |
@TrySound Go ahead. |
@Victorystick I don't have access for this repo :) |
@TrySound Oops. How about now? |
@Victorystick Yep. Thanks. |
@Victorystick I can't seem to find any |
@dralletje Sorry, I meant |
👍 please. I, also, am trying to bundle with |
@dralletje this looks like it almost addresses an issue I have with code that has been pre-compiled with babel having https://github.com/ParsePlatform/Parse-SDK-JS/blob/master/src/Parse.js The compiled code will result in var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
var _interopRequireWildcard = require('babel-runtime/helpers/interop-require-wildcard')['default']; and with my config const babelrc = {
babelrc: false,
runtimeHelpers: true,
presets: ['es2015-rollup', 'stage-0'],
plugins: ['transform-decorators-legacy']
};
const src = path.join(srcDir, scriptDir);
const srcGlob = path.join(src, '{*.js,**/*.js}');
const hfaGlob = 'node_modules/@hfa/{js-api-wrappers,validator}/lib/{*.js,**/*.js}';
rollup({
entry,
plugins: [
babel({
...babelrc,
sourceMaps: true,
include: [
srcGlob,
hfaGlob
]
}),
nodeResolve({
extensions: ['.js'],
main: true,
browser: true,
preferBuiltins: false
}),
commonjs({
include: [
'node_modules/**/*.js'
],
exclude: [
...hfaGlobs
]
})
]
}).then((bundle) => { without your fix will result in var require$$9$1 = (createClass && typeof createClass === 'object' && 'default' in createClass ? createClass['default'] : createClass);
var _createClass = require$$9$1['default'];
var _classCallCheck = require$$2$28['default']; resulting in
with your branch I get var createClass$1 = (createClass && typeof createClass === 'object' && 'default' in createClass ? createClass['default'] : createClass);
var require$$9$1 = Object.freeze({
default: createClass$1
});
var _createClass = ('default' in require$$9$1 ? require$$9$1['default'] : require$$9$1)['default'];
var _classCallCheck = ('default' in require$$8$2 ? require$$8$2['default'] : require$$8$2)['default']; which still throws the same error but looks a lot closer to working, except for the trailing |
Uhh any updates regarding this? I'm stuck here. Thanks! |
What's the status of this PR? Is there an alternative (specifically for including react-redux), or should this be merged in? |
@dralletje Can you rebase PR and I will merge it. |
@TrySound @dralletje I can do a fork and implement this feature if that is ok. I cannot run react-redux without it. Give me a ping and I will do a fork and implement it. |
Would be great. |
@dralletje Is that okay for you? |
Okay, made progress. Protobuf test is failing for me. I will try to sort that out over the weekend. |
@raphaelokon Heh, look at my PR :) |
I did now :-) I was traveling yesterday and just got the chance to tackle it. Anyways was good to look into the internals. |
Protobuf failed without full interop checking. |
Hey @raphaelokon , ofcourse that is okay :-) I hope you can use the logic in this PR so you don't have to figure out everything yourself again! |
@dralletje Cheers on that. @TrySound already did a PR that incorporates your stuff. Probably this and the defaultInterop PR can be closed then? |
@raphaelokon Let's wait until Rich will publish it tomorrow. |
Did you try to build it with copy pasta build of the last release? |
@TrySound Sorry, not sure I follow. I just implemented the feature for non-default exports on top of the current version. All tests (except the protobuf) were passing. |
I meant your react redux project. Is it work with the latest changes. You may pull master, build code and copy paste to your node_modules. |
Ah … gotcha :> Will have to check tomorrow, but will defo let you know here. |
Published 3.2.0 |
Fixes rollup/rollup#524
Will allow commonjs modules to import es modules when no default is defined. A lot of modules still rely on the nodejs way: The ability to import an object of exports when using
require
. Rollup didn’t allow that, until now :)