ES(ES6 Module) Import Path Resolution

参考: https://github.com/nodejs/node-eps/blob/4217dca299d89c8c18ac44c878b5fe9581974ef3/002-es6-modules.md#51-determining-if-source-is-an-es-module

ES import statements will perform non-exact searches on relative or absolute paths, like require(). 
This means that file extensions, and index files will be searched,

In summary:

// looks at
//   ./foo.js
//   ./foo/package.json (需要配合package.json配置文件中的main/module配置项)
//   ./foo/index.js
//   etc.
import './foo';
// looks at
//   /bar.js
//   /bar/package.json 
//   /bar/index.js
//   etc.
import '/bar';
// looks at:
//   ./node_modules/baz.js
//   ./node_modules/baz/package.json
//   ./node_modules/baz/index.js
// and parent node_modules:
//   ../node_modules/baz.js
//   ../node_modules/baz/package.json
//   ../node_modules/baz/index.js
//   etc.
import 'baz';
// looks at:
//   ./node_modules/abc/123.js
//   ./node_modules/abc/123/package.json
//   ./node_modules/abc/123/index.js
// and parent node_modules:
//   ../node_modules/abc/123.js
//   ../node_modules/abc/123/package.json
//   ../node_modules/abc/123/index.js
//   etc.
import 'abc/123';

results matching ""

    No results matching ""