0

I am writing a JS library. The core file of the library is an ES6 file that exports a default class, which sits in the following location './lib/myclass'

I want users of my library to be able to import the the library from the root of the repository. To achieve this in ES5 I can put the following into an index.js file at the root:

module.exports = require('./lib/myclass');

How can I do this using default exports in ES6? I would also like to use the ES6 way of importing. I realise that I can still do it the ES5 way, but I am just trying to understand how these new statements work.

Thanks

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
SheedySheedySheedy
  • 506
  • 1
  • 6
  • 14

1 Answers1

3

Import the default export and export it again, as default:

import myclass from './lib/myclass';
export default myclass;

I believe the following should work as well, at least it compiles in Babel:

export {default as default} from './lib/myclass';
Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111