unrequire

0.5.4 • Public • Published

UNREQUIRE.JS IS CURRENTLY UNSTABLE. DO NOT USE IT IN PRODUCTION SYSTEMS!

Unrequire.JS

Unrequire.JS is a module definition and inclusion system. It partially implements the AMD JS specification.

Module resolution

Unrequire.JS maintains two pieces of information required to resolve module names. The base path determines the "root" of a project. The current directory determines how explicitly relative module names are resolved.

Example

The module resolution system is best explained through example. Say we have the base path and current directory:

base path = http://example.com/js/
current directory = (empty)

Let's include a module located in http://example.com/js/main.js. It looks like this:

define(function () { alert("Hello, world!"); });

There are three ways we can include this module.

  1. require([ "main" ])
  2. require([ "./main" ])
  3. require([ "/js/main" ])

Option 1 is the recommended method. It concatenates the base path and the module name to locate the script. In this case, http://example.com/js/ ++ main = http://example.com/js/main. The .js extension is automatically included, resulting in the desired http://example.com/js/main.js.

Option 2 is an alternative method. It concatenates the base path, the current directory, and the module name. Options 2 is triggered when a path begins with ./ or ../. In this case, http://example.com/js/ ++ (empty) ++ main = http://example.com/js/main. The .js extension is inserted, as with option 1.

Option 3 is discouraged, as it depends on the location of the module script on the file system or web server. Option 3 is triggered when a path begins with a "/".

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.49latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.49
0.5.30
0.5.20
0.5.10
0.5.00
0.4.20
0.4.10
0.4.00
0.3.70
0.3.60
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.00
0.2.10
0.2.00
0.1.20
0.1.10
0.1.00

Package Sidebar

Install

npm i unrequire

Weekly Downloads

9

Version

0.5.4

License

none

Last publish

Collaborators

  • strager