alone.js

1.0.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i alone.js

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • toxichl