项目原始demo,不改动
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # import-from [![Build Status](https://travis-ci.org/sindresorhus/import-from.svg?branch=master)](https://travis-ci.org/sindresorhus/import-from)
  2. > Import a module like with [`require()`](https://nodejs.org/api/globals.html#globals_require) but from a given path
  3. ## Install
  4. ```
  5. $ npm install --save import-from
  6. ```
  7. ## Usage
  8. ```js
  9. const importFrom = require('import-from');
  10. // There is a file at `./foo/bar.js`
  11. importFrom('foo', './bar');
  12. ```
  13. ## API
  14. ### importFrom(fromDir, moduleId)
  15. Like `require()`, throws when the module can't be found.
  16. ### importFrom.silent(fromDir, moduleId)
  17. Returns `null` instead of throwing when the module can't be found.
  18. #### fromDir
  19. Type: `string`
  20. Directory to import from.
  21. #### moduleId
  22. Type: `string`
  23. What you would use in `require()`.
  24. ## Tip
  25. Create a partial using a bound function if you want to import from the same `fromDir` multiple times:
  26. ```js
  27. const importFromFoo = importFrom.bind(null, 'foo');
  28. importFromFoo('./bar');
  29. importFromFoo('./baz');
  30. ```
  31. ## Related
  32. - [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory
  33. - [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
  34. - [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of a module from the current working directory
  35. - [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
  36. - [import-lazy](https://github.com/sindresorhus/import-lazy) - Import modules lazily
  37. ## License
  38. MIT © [Sindre Sorhus](https://sindresorhus.com)