Skip to content
/ ocean Public
forked from nqdeng/ocean

A experimental module loader with the same APIs of SeaJS(https://seajs.org).

Notifications You must be signed in to change notification settings

lianqin7/ocean

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ocean

A experimental module loader with the same APIs of SeaJS(https://seajs.org).

API Reference

define(id, dependencies, factory)

Define a module.

define('foo.js', [ 'bar.js' ], function (require, exports, module) {
	var bar = require('bar.js');
	require.async('baz.js', function (baz) {
		// ...
	});
	// ...
});

seajs.use(id, callback)

Use modules by id. 'callback' is executed when all modules ready.

seajs.use('foo', function (foo) {
	// ...
});

seajs.use([ 'bar', 'baz' ], function (bar, baz) {
	// ...
});

seajs.config(option)

Deep-merge configuration in option object with existing ones.

seajs.config({
	alias: {
		'foo': 'https://foo.com',
	},
	base: 'https://bar.com/',
	charset: 'utf-8'
});

seajs.before(methodName, handler)

Add an AOP handler before an internal method.

seajs.before('load', function (uris) {
	return [ combo(uris) ];
});

seajs.after(methodName, handler)

Add an AOP handler after an internal method.

seajs.after('resolve', function (uri) {
	return map(uri);
});

Module ID

Module ID is a unique full URI assigned with a module. Module ID could write in partial or alias form but will be resolved to full URI finally.

Full URI

Full URI is used as it is.

seajs.use('https://foo.com/bar.js');

Partial URI

Partial URI could be a relative pathname or a absolute pathname. In HTML page, relative pathname is resolved based on page URI. In a module, relative pathname is resolved based on module ID. And absolute pathname is always resolved based on seajs base configuration.

# in https://foo.com/index.html
seajs.use('./bar.js') // equals => seajs.use('https://foo.com/bar.js')

# in https://foo.com/bar.js
require('./baz.js') // equals => require('https://foo.com/baz.js')

# base is configured to 'https://foo.com/bar/'
require('baz.js') // equals => require('https://foo.com/bar/baz.js')

Alias

If module ID is writen in absolute pathname, the first part could be an alias.

# define alias: 'bar': 'https://foo.com/bar'
require('bar/baz.js') // equals => require('https://foo/bar/baz.js')

Prepend # to ID can prevent alias parsing.

# define alias: 'bar': 'https://foo.com/bar'
# base is configured to 'https://foo.com/bar/'
require('#bar/baz.js') // equals => require('https://foo/bar/bar/baz.js')

Extname

If a URI does not have an extname, or not contain ?, .js is appended to URI by default.

# in https://foo.com/bar.js
require('./baz') // equals => require('https://foo.com/baz.js')

Append '#' to ID can prevent default extname appending.

# in https://foo.com/bar.js
require('./baz#') // equals => require('https://foo.com/baz')

About

A experimental module loader with the same APIs of SeaJS(https://seajs.org).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published