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

Support creating index with default export #61

Open
bmish opened this issue Dec 29, 2021 · 9 comments
Open

Support creating index with default export #61

bmish opened this issue Dec 29, 2021 · 9 comments

Comments

@bmish
Copy link

bmish commented Dec 29, 2021

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)?

@gajus
Copy link
Owner

gajus commented Jan 3, 2022

Open to it. As long as it is behind a flag, I see no harm.

@tjjfvi
Copy link

tjjfvi commented Jan 4, 2022

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.

@ChocolateLoverRaj
Copy link

I need an index file with a default-exported object.

@bmish why?

@ChocolateLoverRaj
Copy link

@bmish But why can't you just export named and use import * as obj?

@bmish
Copy link
Author

bmish commented Mar 11, 2022

@ChocolateLoverRaj I'm unclear what you mean by that. Can you show an example?

@bmish
Copy link
Author

bmish commented Mar 12, 2022

@ChocolateLoverRaj I'm not sure how that helps me. I need to re-export every file in a directory.

@ChocolateLoverRaj
Copy link

@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

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

4 participants