OneJS is a command-line utility for converting CommonJS packages to single, stand-alone JavaScript
files that can be run on other JavaScript platforms such as web browsers, unity, silkjs etc.
Motivation
- Reusability OneJS aims to let developers run NodeJS modules and packages on all environments able to execute JavaScript.
- Elegant Modularization OneJS lets web projects benefit from CommonJS, an excellent proposal that gives us a very well designed way to structure JavaScript source codes.
- NPM It eventually makes it possible for web projects to use NPM. Which is a great tool that makes controlling dependencies even fun!
- No Spaghetti Code No awkward headers, no framework-specific definitions which become deprecated in a few years.
- Reliable code generation OneJS doesn't change your source code. It only generates a container environment that simply emulates NodeJS environment.
- Unobtrusive Code OneJS generates puts all content into an isolated JS object.
Examples
- See the example project included in this repository
- See MultiplayerChess.com's source code.
Install
$ npm install one
- Tip: Pass -g parameter to install it globally. *
First Steps
Testing Example Project
It's an easy way to give OneJS a test-drive. Example project is located at this repository;
$ git clone git@github.com:azer/onejs.git
$ cd onejs
$ npm install
$ cd example-project
It's a non-functional NodeJS project with some dummy dependencies under node_modules directory. The built file will contain all the packages under node_modules directory;
$ ../bin/onejs build package.json bundle.js
Now we're willing to test the code OneJS generated for us. Quickest way might be requiring it from NodeJS;
> var exampleProject = require('./bundle');
> exampleProject.main() // calls main module of the package, returns its exports
> exampleProject.require('./b') // each package object has a require method available for external calls
To test it on web browsers, OneJS has a "server" command that builds the source code and start serving it at localhost:1338.
$ ../bin/onejs server example-project/package.json
You can simply go to that URL and inspect the content of "exampleProject" object, using Firebug Lite. The whole source code with
dependencies (if exists) is wrapped by it. It also provides an external API for the possible clients, containing some methods
such as require, main, stdin, stdout, stderror.
> exampleProject.require('dependency'), exampleProject.require('./b');
> exampleProject.lib.process.stdout.write("Hello World");
> exampleProject.stdout();
"Hello World"
Projects Using OneJS
Beginner's Guide
FIXME
API Reference
FIXME