Import behaviour when file/folder has the same name

Viewed 902

ES6 newbie here. Maybe it's an easy question, but haven't found any useful info on this. I have modals.js file and modals folder in actions directory.

How can I tell javascript whether I want to import a file or a folder if they have same name?

My expectation is that:

import {...} from './actions/modals' 

Can be treated either as modals.js file or modals/index.js. Is there any widely spread solution that will work on any bundler, that will guarantee what exactly do I require?

I understand that I can try to use '.js' extension like:

import {...} from './actions/modals.js'

But my research shown that not all builders support file extension.

I would really appreciate your help in my ES6 learning

1 Answers

Combining everything that was mentioned in the comments I've ended up in a way to always specify either / in the end if I refer to a folder or .js if I refer to specific file.

Related