https://github.com/zweifisch/simple-require
nodejs like require/exports for browser
https://github.com/zweifisch/simple-require
Last synced: 4 months ago
JSON representation
nodejs like require/exports for browser
- Host: GitHub
- URL: https://github.com/zweifisch/simple-require
- Owner: zweifisch
- Created: 2013-01-14T14:55:45.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-03-22T02:29:45.000Z (about 12 years ago)
- Last Synced: 2025-01-17T09:41:20.814Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 207 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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`
```html```
content of `lib/my-math-helpers.js`
```javascript
exports.version = 'v0.0.1';
exports.divide = function(n,n2){
return Math.floor(n/n2);
}
```content of `lib/my-time-helpers.js`
```javascript
var math = require('./my-math-helpers');
exports.getTimestamp = function(){
return math.divide(+new Date(),1000);
}
```finally `main.js`
```javascript
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
install simple-require via npm
```sh
npm install -g simple-require
``````sh
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
```html```
when packing scripts, use the `--shims` option
### more options
using `--list-dependency` or `-l` for short to list dependencies of a file
```sh
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
```sh
simple-require --concat-scripts build.txt >! build.js
```