Skip to content

Commit

Permalink
Make work with Browserify.
Browse files Browse the repository at this point in the history
This depends on heapwolf/codesurgeon#13 being accepted. Once it is, and the codesurgeon dependency is updated, the existing build script will produce a file that can be used either with <script> tag includes, or with browserify (and any other browser-based CommonJS module loaders).

Furthermore, this adds a "browserify" entry in package.json pointing to the browser-built file, so that users can just do `require("director")` instead of `require("director/build/director-1.1.3")`.
  • Loading branch information
domenic committed Jul 27, 2012
1 parent de03237 commit 69e23d4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.idea/
node_modules
npm-debug.log
.DS_Store
.DS_Store

/test/browser/browserified-bundle.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"vows": "0.6.x"
},
"ender": "./build/ender.js",
"browserify": "./build/director-1.1.3",
"main": "./lib/director",
"engines": {
"node": ">= 0.4.0"
Expand Down
24 changes: 24 additions & 0 deletions test/browser/browserify-harness.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Director Browserify Tests</title>
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css">
</head>
<body>
<p>To run these tests first generate a Browserify bundle for director by running the command <kbd>browserify -r ../director -o test/browser/browserified-bundle.js</kbd> in the repo's root directory.</p>

<div id="qunit">
<div id="qunit-fixture"></div>

<script src="browserified-bundle.js"></script>
<script>
var HTML5TEST = false;
var RouterAlias = require('/director-1.1.3').Router;
</script>

<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="helpers/api.js"></script>
<script src="routes-test.js"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions test/browser/helpers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module("Director.js", {
var shared;

function createTest(name, config, use, test, initialRoute) {
// We rename to `RouterAlias` for the browserify tests, since we want to be
// sure that no code is depending on `window.Router` being available.
var Router = window.Router || window.RouterAlias;

if (typeof use === 'function') {
test = use;
use = undefined;
Expand Down

0 comments on commit 69e23d4

Please sign in to comment.