browser-require
Advanced tools
Comparing version 0.0.3 to 0.1.1
{ | ||
"name": "browser-require", | ||
"description": "Use CommonJS and NPM modules from the browser", | ||
"version": "0.0.3", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/bnoguchi/browser-require", | ||
"repository": "https://github.com/bnoguchi/browser-require.git", | ||
"author": "Brian N Noguchi <brian.noguchi@gmail.com> (https://github.com/bnoguchi)", | ||
"main": "./browser-require.js", | ||
"main": "./lib/browser-require.js", | ||
"directories": { | ||
"lib": "" | ||
}, | ||
"bin": { | ||
"browser-require": "./bin/browser-require" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"dependencies": { | ||
"expresso": ">= 0.7.2", | ||
"dependency-promise": ">=0.2.0" | ||
}, | ||
"engines": { | ||
@@ -16,0 +23,0 @@ "node": ">=0.2.6" |
browser-require | ||
=============== | ||
#### The easiest way to require CommonJS and NPM modules in your browser | ||
browser-require | ||
#### The easiest way to require and use CommonJS and NPM modules from your browser | ||
@@ -15,8 +14,11 @@ Npm makes it easy to share code on your server. But how many times have you | ||
### Getting started | ||
### Installation | ||
To install: | ||
$ npm install browser-require | ||
### Using browser-require within your connect app | ||
Currently, browser-require depends on the | ||
[connect](https://github.com/visionmedia/connect/) middleware framework. | ||
[connect](https://github.com/visionmedia/connect/) middleware framework, | ||
if you want to serve client javascript files that contain `require`s. | ||
@@ -44,5 +46,2 @@ First, add in the browser-require middleware into your `connect` server: | ||
<body> | ||
<!-- This is a boilerplate file that you must require --> | ||
<script type="text/javascript" src="/browser_require.js"></script> | ||
<!-- This is where your custom JavaScript code resides. See README section below --> | ||
@@ -63,21 +62,18 @@ <script type="text/javascript" src="/js/app.js"></script> | ||
### How it works | ||
Currently, all requires from the browser load JavaScript source and dependencies | ||
from the server in a dynamic, piece-wise, and on-demand fashion. | ||
When you request a javascript file: | ||
1. The server looks up the source and its module dependencies, if any. | ||
2. The server sends back the stringified source (SSRC) and its dependencies. | ||
3. If there are dependencies, then for each dependency, repeat from step 1. | ||
4. Once each javascript file has loaded all its dependencies, then eval and load the SSRC for the file. | ||
1. The server looks up the source and its module dependencies (if any) recursively. | ||
2. Once the server has collected all dependencies, it compiles the top-level file plus | ||
its dependencies into a file that gets sent back to the browser. | ||
The above methodology is great for development environments, where you do not constantly want to | ||
re-compile a javascript file and its dependencies into a single static JavaScript file. | ||
### Command line binary | ||
Sometimes you need to statically compile a set of javascript client files from the command line. | ||
For example, this is necessary if you are building a Chrome plugin. A Chrome plugin can use JavaScript | ||
files that exist inside the Chrome plugin (as opposed to fetching a JavaScript file that exists on the | ||
server). Therefore, it is necessary in this case to compile your JavaScript files and their dependencies | ||
outside of the context of a server. | ||
That said, I will be adding static compilation shortly for use in production environments. | ||
`browser-require` supports this via a command line binary. You can use it in the following way: | ||
$ browser-require path/to/js/file.js > path/to/compiled/js/file.js | ||
Moreover, there are plans to be able to use a hybrid approach for doing both static compilation and | ||
dynamic loading in the same environment, selectively depending on what you want to pre-compile and | ||
what you want to load dynamically. | ||
### Examples | ||
@@ -117,3 +113,2 @@ There are examples in the [./examples](https://github.com/bnoguchi/browser-require/tree/master/examples) directory. | ||
### Planning on implementing | ||
- Static compilation of all CommonJS dependencies into a single JavaScript file. | ||
- A middleware filter mechanism to include things such as a Google Closure Compiler filter. | ||
@@ -120,0 +115,0 @@ |
@@ -45,4 +45,4 @@ var rel = require('./rel') | ||
}); | ||
asyncTest('npm modules that use relative modules', function () { | ||
// The following file requires ./entities; | ||
asyncTest('npm modules that use relative modules from a file under the npm lib dir', function () { | ||
// The following file requires ./entities | ||
// See https://github.com/chriso/node-validator/blob/master/lib/xss.js | ||
@@ -53,1 +53,8 @@ var clean = require('validator/xss').clean; | ||
}); | ||
asyncTest('npm modules that use relative modules from the main file', function () { | ||
// The following file requires ./lib/async from the 'main' index.js package file | ||
// See https://github.com/caolan/async/index.js | ||
var noConflict = require('async').noConflict; | ||
equals('function', typeof noConflict); | ||
start(); | ||
}); |
@@ -1,13 +0,14 @@ | ||
require.paths.unshift('..'); | ||
require.paths.unshift('../../lib'); | ||
var path = require('path'); | ||
require.paths.unshift(path.join(__dirname, '..', '..')); | ||
var connect = require('connect'); | ||
var app = connect.createServer(); | ||
var exposeRequire = require('browser-require'); | ||
app.use(exposeRequire({ | ||
base: __dirname | ||
})); | ||
app.use(connect.staticProvider(__dirname)); | ||
var app = connect.createServer( | ||
exposeRequire({ | ||
base: __dirname | ||
}), | ||
connect.staticProvider(__dirname) | ||
); | ||
app.listen(1234); | ||
console.log("Server running at http://127.0.0.1:1234"); | ||
process.title = "brtest"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
147931
50
2441
2
121
5
4
+ Addeddependency-promise@>=0.2.0
+ Addedexpresso@>= 0.7.2
+ Addeddependency-promise@0.2.1(transitive)
+ Addedexpresso@0.9.2(transitive)