Code Monkey home page Code Monkey logo

lithe's Introduction

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

lithe's People

Contributors

myluluy avatar tabspace avatar xiaojue avatar zhangzhaoaaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lithe's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.