Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked from xiaojue/lithe

A browser-side script loader,compatible with the de facto standards(NodeJS/CommonJS).

License

Notifications You must be signed in to change notification settings

shenmeng03/lithe

Repository files navigation

Lithe

Build Status 依赖模块状态

A browser-side script loader,compatible with the de facto standards(NodeJS/CommonJS). It's very simple and small,only 2.7kb gzipped.

If you use Gruntjs to build your project , you can use grunt-lithe

You can use bower manage modules Easier.

Chinese Documentation 中文文档


Installation

$ npm install lithe -g
$ git clone https://github.com/litheModule/lithe
$ cd lithe
$ npm install -d

command tools


$ lithe 
 Usage: lithe [options] [command]
 Commands:
 build <source> <target> build source to target
 compress <source> <target> compress source to target
 getpackage <source> <target> get source requires to target package
 Options:
 -h, --help output usage information
 -V, --version output the version number
 -c, --config <path> set the config file,it will be return alias and basepath
 

public api for browser

define

//path/to/file.js
define('path/to/file',function(require,exports,module){
 var file = 'path/to/file.js';
 exports.filename = 'file.js';
 exports.filedir = 'path/to/';
 /**
 * module.exports = {
 * filename:'file.js',
 * filedir:'path/to'
 * };
 */
});

require

//path/to/app.js
define('path/to/app',function(require,exports,module){
 var file = require('path/to/file');
 console.log(file.filename); //file.js
 console.log(file.filedir) //path/to
 module.exports = 'i am app.js';
});

lithe.use

//anywhere
lithe.use('path/to/app',function(app){
 console.log(app); // i am app.js
});
//or
lithe.use('a.js','b.js',function(a,b){
 //a and b has required;
});

config

define('config',function(require,exports,module){
 module.exports = {
 //it will replace the real BASEPATH
 basepath:'http://localhost/debug/path', 
 //logogram
 alias:{
 'app':'path/to/app',
 'file':'path/to/file',
 //Relative directory proxy
 'UI':'../'
 }
 };
});
define('someOtherJs',function(){
 var app = require('app'),
 file = require('file');
});

public api for node

//npm install lithe
var lithe = require('lithe'),
tool = lithe.tool,
hfs = lithe.hfs,
options = tool.options;
options.basepath = 'your project base dir';
options.uglifyPath = 'your uglifyjs dir';
options.alias = {}; //your short alias config

tool.findJsAllrequires([filepath])

var requires = tool.findJsAllrequires('../app.js');
//app.js's requires are findout and alias will be replaced 

tool.concatFile([files],[target])

tool.concatFile(['/path/to/file1.js','/path/to/file2.js'],'/path/to/file1&file2.js');
//file1 and file2 will be merger

tool.uglifyJs([filepath],[target])

tool.uglifyJs('/path/to/file1&file2.js','path/to/file1&file2-min.js');
//Equivalent uglifyjs --reserved-names require -o path/to/file1&file2-min.js /path/to/file1&file2.js

hfs.cpdirSync([sourceDir],[targetDir])

hfs.cpdirSync('/path/to/dir1','/path/to/dir2');
//copy the folder by sync,if targetDir not exist it will be created.
//.git and .svn will be continue.

hfs.delSync([path])

hfs.delSync('/path/to/dir');
hfs.delSync('/path/to/file');
//del the folder or file sync
//.git and .svn will be continue.

hfs.mkdirSync([target])

hfs.mkdirSync('/path/dir')
//if the '/path' folder not exist,it will be created.

hfs.walk([path],[callback],[options])

hfs.walk('/path/',function(files){
 console.log(files); 'return path folder all js files'; 
},{
 filter:function(file){
	 if (path.extname(el).indexOf('.js') > - 1) return true;
 }
});
//it's worked sync

hfs.writeFileSync([filepath],[data],[encoding = utf8])

hfs.writeFileSync('/path/file',"abcd");
//if path folder not exist,it will be created.

How to deploy in the web browser?

<script src="lithe.js"
 data-config="config.js"
 data-path="http://domain.com/"
 data-debug="true"
 data-main="app.js">
</script>

License

BSD license

About

A browser-side script loader,compatible with the de facto standards(NodeJS/CommonJS).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.3%
  • HTML 3.7%

AltStyle によって変換されたページ (->オリジナル) /