Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # node-ensure
  2. A simple library that shims asynchronous module loading into Node.js to help
  3. with building module bundlers and client-side loaders for isomorphic apps.
  4. This library is super slim (read the source) and mainly represents an agreement
  5. between developers and users of a particular bundler/loader.
  6. NOTE: This module is *not* compatible with Browserify. It is for developers that
  7. want to split their bundles for the client. For example, see
  8. [dynapack](https://github.com/bauerca/dynapack).
  9. *Syntax is inspired by the CommonJS
  10. [Modules/Async/A](http://wiki.commonjs.org/wiki/Modules/Async/A) proposal.*
  11. ## Installation
  12. ```
  13. npm install node-ensure
  14. ```
  15. ## Example
  16. ```js
  17. var ensure = require('node-ensure');
  18. ensure(['superagent', 'react'], function(err) {
  19. var request = require('superagent');
  20. var React = require('react');
  21. // Do the coolest of things.
  22. });
  23. ```
  24. If your bundler needs `require.ensure`, do this instead:
  25. ```js
  26. require.ensure = require('node-ensure');
  27. require.ensure(['superagent', 'react'], function(err) {
  28. var request = require('superagent');
  29. var React = require('react');
  30. // Do the coolest of things.
  31. });
  32. ```
  33. ## Usage
  34. The returned function takes an array of strings and a callback, in that
  35. order (see the example above). The callback takes a single error argument, which
  36. usually indicates a network problem or other client-side loader-specific runtime
  37. error (it should never receive an error when used in Node.js).
  38. Within the ensure callback, load modules with standard require calls.
  39. ## Bundlers/Loaders
  40. This library primarily constitutes an agreement between users and developers of
  41. module bundlers and (client-side) loaders. The users agree to the usage instructions
  42. supplied above.
  43. Bundlers and/or loaders must adhere to the following:
  44. - The bundler/loader uses the package.json `"browser"` property for replacing
  45. server-only modules with browser-ready counterparts (a la Browserify).
  46. - The `require` function passed to a module must have a `require.ensure`
  47. function.
  48. - Each `require.ensure` must accept the same arguments as described in [Usage](#usage).
  49. - Each `require.ensure` must not access variables via closure unless those variables
  50. are shared by **all** `require.ensure` functions.
  51. - Each `require.ensure` may access properties
  52. on `this`. However, this assumes users have attached node-ensure to `require` via
  53. `require.ensure = require('node-ensure')`.
  54. Happy loading!
  55. # License
  56. MIT