Ben Aston Ben Aston - 1 month ago 6
Javascript Question

Avoiding the "default" property indirection with babel

I am using babel to transpile ES2015 code to ES5 & RequireJS.

But when I use the following syntax:

const o = { foo: 'foo' };
export default o;


The transpiled result is an object with a
default
property on it.

ie. it is currently transpiled to something like:

define(function() {
return {
default: {
foo: 'foo'
}
};
});


What I want is the object literal itself (containing the foo property) to be returned directly.

ie. I want something like:

define(function() {
return {
foo: 'foo'
};
});


Can I achieve this?

Answer

If you don't include default it will work as expected.

export const o = { foo: 'foo' };
Comments