0.2.1 • Published 5 years ago

rqjs v0.2.1

Weekly downloads
25
License
-
Repository
-
Last release
5 years ago

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.

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

1.0.0

7 years ago