create-index
create-index copied to clipboard
Support creating index with default export
Currently, this plugin only supports creating an index with named exports. I need an index file with a default-exported object.
Example:
import foo from './foo.js';
import bar from './bar.js';
import _3_x_recommended from './3-x-recommended.js'; // note unsafe variable name needs to be tweaked
export default {
foo,
bar,
'3-x-recommended': _3_x_recommended
};
I see this functionality is in a forked version of this tool: https://github.com/tjjfvi/create-index-better#modes
// @create-index {"mode":"default{}"}
import foo from './foo.js'; import bar from './bar.js'; export default { foo, bar };
Has it been considered for the original create-index
? @tjjfvi would you consider upstreaming this functionality (and presumably any other improvements from the fork)?
Open to it. As long as it is behind a flag, I see no harm.
I definitely support any improvements from create-index-better being upstreamed. I haven’t the bandwidth to do that atm, but I’m happy to interface with someone who does if that’s helpful.
I need an index file with a default-exported object.
@bmish why?
Example of the index file I need to generate:
- https://github.com/ember-template-lint/ember-template-lint/blob/master/lib/config/index.js
- https://github.com/ember-template-lint/ember-template-lint/blob/master/lib/rules/index.js
@bmish But why can't you just export named and use import * as obj
?
@ChocolateLoverRaj I'm unclear what you mean by that. Can you show an example?
@bmish https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_an_entire_modules_contents
@ChocolateLoverRaj I'm not sure how that helps me. I need to re-export every file in a directory.
@bmish In the file you can do this:
// letters.js
export const a = 0
export const b = 1
export const c = 2
Instead of default export. Then In the file you want to import the first file with you can do this:
import * as letters from './letters.js'
letters.a // 0
letters.b // 1
letters.c // 2