0.0.7 • Published 11 years ago

simple-require v0.0.7

Weekly downloads
12
License
-
Repository
github
Last release
11 years ago

simple-require

nodejs like require/exports for browser

how to use

asumming following project structure

index.html
main.js
lib
	my-math-helpers.js
	my-time-helpers.js
vender
	simplre-require.js

include simplre-require.js in index.html, data-main="main" here claims that the entry script is main.js

<script data-main="main" type="text/javascript" src="vender/simple-require.js"></script>

content of lib/my-math-helpers.js

exports.version = 'v0.0.1';
exports.divide = function(n,n2){
	return Math.floor(n/n2);
}

content of lib/my-time-helpers.js

var math = require('./my-math-helpers');
exports.getTimestamp = function(){
	return math.divide(+new Date(),1000);
}

finally main.js

var time = require('./lib/my-time-helpers');
console.log(time.getTimestamp());

why use it

  • code sharing between browser and nodejs made easy
  • simplicity(about 100 lines of coffeescript)

how to pack

pack manually

prepare a build.txt, the entry script must be placed at the top of it

main
lib/my-math-helper
lib/time-helper

then run

simple-pack --concate-scripts build.txt >! build.js

there is also a --minify option, if set, the concated script will be passed to uglify-js

pack automatically

TBD

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago