Looking on the internet I'm confused with the special "index.js" module file.
Using babelJS + nodeJS or Browserify/Webpack I can import an "index.js" module inside a "libs" directory using import myLib from "./libs"
(ie. omitting the /index
or /index.js
part).
Is the "index.js" module resolution (specifying the containing folder) supported by the ES6 (EcmaScript 2015) modules official standard? Or is it just "custom" NodeJS/CommonJS transpiling behaviour?
Will it be possible to omit the /index
|/index.js
part of the import in all browsers as well (when modules will be supported on all browsers)?
No. ES2015 doesn't contain anything about the module loader or how to interpret module identifiers.
Yes. You can read about the module resolution algorithm in the documentation. The relevant part:
Hopefully browser implementation will aim for maximum compatibility with existing module loaders, but for now we don't know. Maybe it doesn't have anything to do with the browser either, but with how to server resolves module identifiers. I confess that I haven't followed the development lately, so any other insights are much appreciated :)