Search code examples
ecmascript-6webpackbabeljses6-module-loader

ES6 Import Folder


Does the ES6 module syntax allow you to import something from a folder?

For example if I have ./sub/main.js and I try import foo from './sub in the ./main.js file, will this work?

Could I get this sort of importing from a folder to work with babel and webpack?

Basically this would be the equivalent of __init__.py in Python.


Solution

  • ES6's module syntax does not dictate how the module identifier should be interpreted.

    That solely depends on the module loader / bundler you are using, which seems to be webpack. Not sure how easily it can be implemented, have a look at the documentation.