版博士V2.0程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <p align="center">
  2. <a href="http://gulpjs.com">
  3. <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  4. </a>
  5. </p>
  6. # rechoir
  7. [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
  8. Prepare a node environment to require files with different extensions.
  9. ## What is it?
  10. This module, in conjunction with [interpret]-like objects, can register any filetype the npm ecosystem has a module loader for. This library is a dependency of [liftoff].
  11. **Note:** While `rechoir` will automatically load and register transpilers like `coffee-script`, you must provide a local installation. The transpilers are **not** bundled with this module.
  12. ## Usage
  13. ```js
  14. const config = require('interpret').extensions;
  15. const rechoir = require('rechoir');
  16. rechoir.prepare(config, './test/fixtures/test.coffee');
  17. rechoir.prepare(config, './test/fixtures/test.csv');
  18. rechoir.prepare(config, './test/fixtures/test.toml');
  19. console.log(require('./test/fixtures/test.coffee'));
  20. console.log(require('./test/fixtures/test.csv'));
  21. console.log(require('./test/fixtures/test.toml'));
  22. ```
  23. ## API
  24. ### `prepare(config, filepath, [cwd], [noThrow])`
  25. Look for a module loader associated with the provided file and attempt require it. If necessary, run any setup required to inject it into [require.extensions].
  26. `config` An [interpret]-like configuration object.
  27. `filepath` A file whose type you'd like to register a module loader for.
  28. `cwd` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`.
  29. `noThrow` An optional boolean indicating if the method should avoid throwing.
  30. If calling this method is successful (e.g. it doesn't throw), you can now require files of the type you requested natively.
  31. An error with a `failures` property will be thrown if the module loader(s) configured for a given extension cannot be registered.
  32. If a loader is already registered, this will simply return `true`.
  33. ## License
  34. MIT
  35. <!-- prettier-ignore-start -->
  36. [downloads-image]: https://img.shields.io/npm/dm/rechoir.svg?style=flat-square
  37. [npm-url]: https://www.npmjs.com/package/rechoir
  38. [npm-image]: https://img.shields.io/npm/v/rechoir.svg?style=flat-square
  39. [ci-url]: https://github.com/gulpjs/rechoir/actions?query=workflow:dev
  40. [ci-image]: https://img.shields.io/github/workflow/status/gulpjs/rechoir/dev?style=flat-square
  41. [coveralls-url]: https://coveralls.io/r/gulpjs/rechoir
  42. [coveralls-image]: https://img.shields.io/coveralls/gulpjs/rechoir/master.svg
  43. <!-- prettier-ignore-end -->
  44. <!-- prettier-ignore-start -->
  45. [interpret]: https://github.com/gulpjs/interpret
  46. [require.extensions]: https://nodejs.org/api/modules.html#modules_require_extensions
  47. [liftoff]: https://github.com/js-cli/js-liftoff
  48. <!-- prettier-ignore-end -->