browserify-loader
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "browserify-loader", | ||
"main": "browserify-loader.js", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/island205/browserify-loader", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "browserify-loader", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Another CommonJS Loader", | ||
@@ -21,3 +21,3 @@ "main": "test/bar.js", | ||
"author": "island205@gmail.com", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -27,3 +27,3 @@ "url": "https://github.com/island205/browserify-loader/issues" | ||
"homepage": "https://github.com/island205/browserify-loader", | ||
"dependencies": { | ||
"devDependencies": { | ||
"path-browserify": "0.0.0", | ||
@@ -30,0 +30,0 @@ "rsvp": "^3.0.12", |
@@ -1,2 +0,66 @@ | ||
browserify-loader | ||
# browserify-loader | ||
================= | ||
A CommonJS Loader for browserify workflow. | ||
## What is browserify-loader | ||
`browserify-loader` is another CommonJS loader for browserify workflow. With BL, You don’t need any tools like watchify, browserify-middleware to auto build and serve bundle *js in development env. | ||
`browserify-loader` is similar with [requirejs](http://requirejs.org/), but: | ||
- follow [Modules/1.1.1](http://wiki.commonjs.org/wiki/Modules/1.1.1) like [Node](http://nodejs.org/) | ||
- get rid of wrapper code like `define()` | ||
- be compatible all `npm` package and all `bower` components witch support `CommonJS`. like `underscore`, `backbone`, `jQuery` and so on. | ||
## Getting start | ||
### install | ||
Download `browserify-loader` with `npm` or `bower`: | ||
```bash | ||
$ npm install browserify-loader | ||
``` | ||
Put `browserify-loader.js` in your page: | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
</head> | ||
<body> | ||
<script type="text/javascript" | ||
src="node_modules/browserify-loader/browserify-loader.js"></script> | ||
</body> | ||
</html> | ||
``` | ||
Then, `browserify-loader` will start to run for `main` file in your `package.json` file. | ||
### options | ||
`browserify-loader` has two options to specify the `main` script or `package` location. | ||
```javascript | ||
<script type="text/javascript" | ||
id="bl-script" | ||
main="backbone/app.js" | ||
package="backbone/" | ||
src="node_modules/browserify-loader/browserify-loader.js"></script> | ||
``` | ||
- **main**: the main entrance script like `app.js` in `node app.js` | ||
- **package** the location where `browserify-loader` to load `package.json`, then get the main entrance from `main` property. | ||
> **main** 's priority is higher the **package** 's. | ||
## example | ||
Look into [todomvc-in-bl](https://github.com/island205/todomvc-in-bl) , which is a demo project based on [todomvc](https://github.com/tastejs/todomvc) to show how to use `browserify-loader`. | ||
@@ -7,31 +7,42 @@ var xhr = require('xhr') | ||
function loadMainModule(mainScriptUri) { | ||
var mainModule = new Module(mainScriptUri) | ||
mainModule.ee.on('loaded', function() { | ||
mainModule.run() | ||
}) | ||
mainModule.load() | ||
} | ||
function bootstrap() { | ||
var blScript = document.getElementById('bl-script') | ||
var package | ||
if (blScript && (package = blScript.getAttribute('package'))) { | ||
package = url.resolve(location.origin, package) + '/package.json' | ||
var packagePath | ||
var mainScriptPath | ||
if (blScript) { | ||
mainScriptPath = blScript.getAttribute('main') | ||
packagePath = blScript.getAttribute('package') | ||
} else { | ||
packagePath = './' | ||
} | ||
else { | ||
package = location.origin + '/package.json' | ||
if (mainScriptPath) { | ||
mainScriptPath = url.resolve(location.origin, mainScriptPath) | ||
loadMainModule(mainScriptPath) | ||
} else { | ||
packagePath = url.resolve(url.resolve(location.origin, packagePath), './package.json') | ||
xhr({ | ||
uri: packagePath, | ||
headers: { | ||
"Content-Type": "application/json" | ||
} | ||
}, function(err, resp, body) { | ||
if (err) { | ||
throw (err) | ||
} | ||
var pkg = JSON.parse(body) | ||
mainScriptPath = pkg.main || 'index.js' | ||
mainScriptPath = url.resolve(packagePath, mainScriptPath) | ||
loadMainModule(mainScriptPath) | ||
}) | ||
} | ||
xhr({ | ||
uri: package, | ||
headers: { | ||
"Content-Type": "application/json" | ||
} | ||
}, function(err, resp, body) { | ||
if (err) { | ||
throw (err) | ||
} | ||
var pkg = JSON.parse(body) | ||
var mainScriptPath = pkg.main || 'index.js' | ||
var mainScriptUri = url.resolve(package, mainScriptPath) | ||
var mainModule = new Module(mainScriptUri) | ||
mainModule.ee.on('loaded', function() { | ||
mainModule.run() | ||
}) | ||
mainModule.load() | ||
}) | ||
} | ||
bootstrap() |
Sorry, the diff of this file is too big to display
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
135655
0
0
3889
67
6
- Removedpath-browserify@0.0.0
- Removedrsvp@^3.0.12
- Removedsearequire@^1.5.2
- Removedurl@^0.10.1
- Removedwolfy87-eventemitter@^4.2.6
- Removedxhr@^1.13.0
- Removeddom-walk@0.1.2(transitive)
- Removedglobal@4.3.2(transitive)
- Removedmin-document@2.19.0(transitive)
- Removedonce@1.1.1(transitive)
- Removedparse-headers@2.0.5(transitive)
- Removedpath-browserify@0.0.0(transitive)
- Removedprocess@0.5.2(transitive)
- Removedpunycode@1.3.2(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedrsvp@3.6.2(transitive)
- Removedsearequire@1.5.3(transitive)
- Removedurl@0.10.3(transitive)
- Removedwolfy87-eventemitter@4.3.0(transitive)
- Removedxhr@1.17.1(transitive)