Permalink
Browse files

new bundler middleware

  • Loading branch information...
1 parent ee676a8 commit ca87bc2d77c00039fc4092be09bef82af2f82161 @cadorn cadorn committed Mar 5, 2012
Showing with 10 additions and 30 deletions.
  1. +5 −13 01-RequireJSModulesToBrowser/main.js
  2. +5 −17 02-RequireJSPackagesToBrowser/main.js
@@ -13,19 +13,11 @@ exports.main = function(onReadyDeferred, options)
app.get(/^\/$/, CONNECT.static(__dirname));
app.get(/^\/loader.js/, CONNECT.static(PATH.dirname(require.resolve("sourcemint-loader-js/loader.js"))));
-
- app.get(/^(\/modules)(\.js)?(\/(.*))?$/, function (req, res)
- {
- var modulesPath = __dirname + "/" + req.params[0];
-
- // TODO: Maybe we can do without this.
- req.url = req.url.substring(10 + req.params[0].length + (req.params[1] || "").length);
-
- // TODO: Make this `connect` compatible.
- BUNDLER.Middleware(modulesPath, __dirname + "/dist", {
- packageIdHashSeed: "__EXAMPLE__"
- }).handle(req, res);
- });
+
+ app.get(/^\/modules(?:\.js)?(\/.*)?$/, BUNDLER.hoist(__dirname + "/modules", {
+ distributionBasePath: __dirname + "/dist",
+ packageIdHashSeed: "__EXAMPLE__"
+ }));
}));
/*TEST*/ if (onReadyDeferred) {
@@ -13,23 +13,11 @@ exports.main = function(onReadyDeferred, options)
app.get(/^\/$/, CONNECT.static(__dirname));
app.get(/^\/loader.js/, CONNECT.static(PATH.dirname(require.resolve("sourcemint-loader-js/loader.js"))));
-
- app.get(/^\/packages\/([^\/]*?)(\.js)?(\/(.*))?$/, function (req, res)
- {
- var modulesPath = __dirname + "/packages/" + req.params[0];
-
- // TODO: Maybe we can do without this.
- req.url = req.url.substring(10 + req.params[0].length + (req.params[1] || "").length);
-
- // TODO: Make this `connect` compatible.
- BUNDLER.Middleware(modulesPath, __dirname + "/dist", {
- packageIdHashSeed: "__EXAMPLE__",
- // NOTE: Can only request rebuild for root bundle at this time. If an additional-load
- // bundle is rebuilt the existing modules will be incorrect (as root bundle was not loaded first).
- // TODO: Rebuild parent bundles if not available, then requested bundle. Need to keep extra meta info for this.
- rebuild: ((req.url === "")?true:false)
- }).handle(req, res);
- });
+
+ app.get(/^\/packages\/([^\/]*?)(?:\.js)?(\/.*)?$/, BUNDLER.hoist(__dirname + "/packages/$1", {
+ distributionBasePath: __dirname + "/dist",
+ packageIdHashSeed: "__EXAMPLE__"
+ }));
}));
/*TEST*/ if (onReadyDeferred) {

0 comments on commit ca87bc2

Please sign in to comment.