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
content of lib/my-math-helpers.js
exportsversion = 'v0.0.1';exports{ return Math;}
content of lib/my-time-helpers.js
var math = ;exports{ return math;}
finally main.js
var time = ;console;
why use it
- code sharing between browser and nodejs made easy
- simplicity(about 100 lines of coffeescript)
how to pack
install simple-require via npm
npm install -g simple-require
simple-require --build main.js >! packed.js
there is also a --minify
option, if set, the concated script will be passed
to uglify-js
including libraries
prepare a text file with a list of libraries inside
vender/jquery
vender/some-other-lib
set the data-shims attribute
when packing scripts, use the --shims
option
more options
using --list-dependency
or -l
for short to list dependencies of a file
simple-require --list-dependency main.js
--json
for json output, --flat
for more simpler output
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-require --concat-scripts build.txt >! build.js