create-index
create-index copied to clipboard
How to create index of named exports?
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.
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.
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?
Same question. I'd like to have a simple plain file with all components from nested dirs.
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 };
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?