Skip to content
/ alone.js Public

A tiny browser-side CommonJS module loader (~539bytes).

Notifications You must be signed in to change notification settings

ulivz/alone.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alone.js

Travis Travis apm apm

A tiny browser-side CommonJS module loader (~539bytes).

中文README请移步:README_zh

Quick Start

import alone.js in <body> of your page :

<script src="https://unpkg.com/alone.js@1.0.1/dist/alone.min.js"></script>

Create two new files add.js, index.js, import in the page:

<script src="add.js"></script>
<script src="index.js"></script>

Content of test.js

;(function () {

    function add(count) {
		return ++count;
	}
	var metadata = {
		name: 'toxichl',
		words: 'Hello World!'
    }
	exports.year = '1994'
	module.exports = {
		add: add,
		metadata: metadata
	};
	// in ES6 you can write like this:module.exports = {add}

}
)()

Content of index.js

;(function () {
	
	var add = require('add')
	var data = require('metadata')
	
	console.log(add(1))   // 2
	console.log(data.name + ' says ' + data.word)   // toxichl says Hello World!
	console.log(year)   // 1994
})()

Does the above wording be similar to the CommonJS wording of node.js?

Statement

This is just a toy, do not use it for the production environment.

About

A tiny browser-side CommonJS module loader (~539bytes).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published