1.0.1 • Published 7 years ago

alone.js v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

alone.js

一个极简的运行在浏览器上的 CommonJS 模块加载器

Quick Start

在你的页面中 body 中引入:

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

新建两个文件 add.jsindex.js, 在页面中引入:

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

test.js的内容:

;(function () {

    function add(count) {
		return ++count;
	}
	var metadata = {
		name: 'Chen Haoli',
		words: 'Hello World!'
    }

	module.exports = {
		add: add,
		metadata: metadata
	};
	// in ES6 you can write like this:module.exports = {add}

}
)()

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!
	})()

是不是写法和 node.jsCommonJS 写法很像?

Quick Start

1.0.1

7 years ago

1.0.0

7 years ago