rqjs
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

rqjs

rqjs is a minimum AMD, CMD module loader for Javascript.

For now it just implement basic functions to keep minimum size.

Intallation

Use yarn to install rqjs:

$ yarn add rqjs

Example

You can define a module by import es module of rqjs:

import rqjs from "rqjs";
 
rqjs.define("moduleA", function() {
  const moduleExport = ...;
  return moduleExport;
})

Or you can define a module with dependencies:

import rqjs from "rqjs";
 
rqjs.define("moduleB", ["moduleA"], function(moduleA) {
  const moduleExport = someFunction(moduleA);
  return moduleExport;
})

Then you can execute a function by:

import rqjs from "rqjs";
 
rqjs.require(["moduleA", "moduleB"], function(moduleA, moduleB) {
  const moduleExport = someFunction(moduleA, moduleB);
  return moduleExport;
})

You can load rqjs.min.js in a HTML page:

<html>
<head></head>
<body>
  <script src="./rqjs.min.js" ></script> 
</body>
</html>

Then rqjs will be mounted on global Object, which is window object in browser.

And you can get it from global environment in your code without import:

rqjs.define(...);
rqjs.require(...)

Finally, you can import modules manually:

const id = "moduleA"
rqjs.config({
  paths: {
    moduleA: MODULE_URL
  }
})
rqjs.import(id).then((moduleExport) => {
  ...
});

Interface

define(id, deps, def)defines a module with unique identify. The id argument is unique identify of module. deps is string array type module's dependencies. And def is the definition function of module. When function excuted, all dependencies would be injected into arguments of the definition function in order.

Readme

Keywords

none

Package Sidebar

Install

npm i rqjs

Weekly Downloads

1

Version

0.2.1

License

none

Unpacked Size

19.9 kB

Total Files

10

Last publish

Collaborators

  • moritaka