Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create index of named exports? #11

Open
deadivan opened this issue Jun 10, 2016 · 5 comments
Open

How to create index of named exports? #11

deadivan opened this issue Jun 10, 2016 · 5 comments

Comments

@deadivan
Copy link

deadivan commented Jun 10, 2016

I use webpack and babel as my es6 transpiler in my dev.create-index act correct when all siblings are files. It breaks when export subdir.

For example

├── king.js
└── queen
    ├── bar.js
    └── foo.js

create-index can correctly build index.js in dir queen

export bar from './bar.js';
export foo from './foo.js';

but in the root dir ,index.js

export queen from './queen'

just export undefined.

I found that

export * as queen from './queen';

worked.

So I forked your code and change the dir export style and committed.

https://github.com/deadivan/create-index

Please tell me if I doing something wrong.

@gajus gajus changed the title dir export style How to create index of named exports? Jun 15, 2016
@gajus
Copy link
Owner

gajus commented Jun 15, 2016

create-index is used to create index only of files that export default. Your code (export * as queen from './queen';) creates an object mapping all named exports. Adding this behaviour to create-index would make index unpredictable (now you know that index is created only for export default value).

I don't think this belongs in the core, but I will leave the issue open in case anyone else has a similar use case and can propose an implementation.

@deadivan
Copy link
Author

Thanks for reply.
Ignoring what i changed,any idea how to export js file under dir queen using create-index? Or my babel setting cause 'undefined' error ? Or we just don't have a proper strategy to generate index recursively?

@viteksafronov
Copy link

Same question. I'd like to have a simple plain file with all components from nested dirs.

@SharpSeeEr
Copy link

I have the same issue. The index.js generated for a directory exports the default export of each file, but not not in itself export a default export. In this case, how can a parent directory re-export the default export of the child directory?

I updated it to work in this situation here although I was getting errors when using this syntax:

export * as queen from './queen';

and instead use this syntax:

import * as queen from './queen';
export { queen };

@ChocolateLoverRaj
Copy link

So I forked your code and change the dir export style and committed.

https://github.com/deadivan/create-index

@deadivan Can you enable issues in your fork?

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

No branches or pull requests

5 participants