17
// before
module.exports = require('./inner.js');
// nowadays
export default from './inner.js';

i'm trying to do this, but babel allow it only in es7 stage 1 as it is proposal for now. So for now, im stick to these two lines:

import sticker from './box-sticker.jsx';
export default sticker;

Can I shorter them to one?

Ryan H.
  • 7,374
  • 4
  • 39
  • 46
Vladimir Starkov
  • 19,264
  • 8
  • 60
  • 114

1 Answers1

32

You should be able to do

export {default as default} from './inner.js';
// or even
export {default} from './inner.js';

with current ES6 semantics.

However I don't think there's anything wrong with using the ES next proposal, I'm pretty confident that it will make it into ES7 ES8.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • 5
    That case can be shortened to `export {default} from './inner.js';` – JMM Aug 26 '15 at 19:58
  • @PhysRex Whether one can omit the file extension or not depends on the module loader that resolves the name, but this has nothing to do with the question – Bergi Jun 10 '18 at 13:09
  • Has this technique/pattern a well-known name? Is this the modern way of the "Module (Design) Pattern" ? – Alex 75 Jan 08 '22 at 12:08
  • @Alex75 I don't see a particular pattern here – Bergi Jan 08 '22 at 14:29