This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeff Balboni
committed
Jun 29, 2016
1 parent
e0b517c
commit eff3b3a
Showing
4 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
# browserify-builder-middleware | ||
# browserify-builder-middleware | ||
|
||
Express middleware for browserify-builder | ||
|
||
##Usage | ||
|
||
``` | ||
var express = require('express'); | ||
var browserifyBuilderMiddleware = require('browserify-builder-middleware'); | ||
var config = require('./builder.config.js'); | ||
var app = express(); | ||
app.use(browserifyBuilderMiddleware(config, { publicPath: appPath, lazy: true})); | ||
``` | ||
|
||
##Options | ||
|
||
- publicPath | ||
- The path to append to the relative output path of the bundles | ||
- lazy | ||
- Only compile app bundles when they are requested | ||
- Default: `false` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
var watchify = require('watchify-middleware'); | ||
var createBuilder = require('browserify-builder'); | ||
var merge = require('lodash/fp/merge'); | ||
|
||
module.exports = function createMiddleware(config, middlewareConfig) { | ||
var builder = createBuilder(merge(config, {parallel: false, options: {cache: {}, packageCache: {}}})); | ||
|
||
var bundles = builder.getBundles(); | ||
|
||
var sharedBundles = bundles.filter(function(bundle) { | ||
return bundle.type === 'shared'; | ||
}).reduce(function(bundleMap, bundle) { | ||
var emitter = watchify.emitter(bundle.bundle, config.watchOptions); | ||
bundleMap[(middlewareConfig.publicPath + bundle.path.replace('\\', '/')).toLowerCase()] = emitter.middleware; | ||
console.log(bundle.path); | ||
return bundleMap; | ||
}, {}); | ||
|
||
var entryBundles = bundles.filter(function(bundle) { | ||
return bundle.type !== 'shared'; | ||
}).reduce(function(bundleMap, bundle) { | ||
var emitter, | ||
middleware; | ||
|
||
if (middlewareConfig.lazy) { | ||
middleware = function middlewareMemoize(req, res, next) { | ||
if (!emitter) { | ||
emitter = watchify.emitter(bundle.bundle, config.watchOptions); | ||
emitter.emit('pending'); | ||
} | ||
return emitter.middleware(req, res, next); | ||
}; | ||
bundleMap[(middlewareConfig.publicPath + bundle.path.replace('\\', '/')).toLowerCase()] = middleware; | ||
} else { | ||
emitter = watchify.emitter(bundle.bundle, config.watchOptions); | ||
bundleMap[(middlewareConfig.publicPath + bundle.path.replace('\\', '/')).toLowerCase()] = emitter.middleware; | ||
} | ||
|
||
return bundleMap; | ||
}, sharedBundles); | ||
|
||
return function middlewareFn(req, res, next) { | ||
var middleware = entryBundles[req.path.toLowerCase()]; | ||
if (middleware) { | ||
middleware(req, res, next); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "browserify-builder-middleware", | ||
"version": "1.0.0", | ||
"description": "Middleware for browserify-builder", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"browserify-tool", | ||
"browserify-builder" | ||
], | ||
"author": "Buildium", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/buildium/browserify-builder-middleware.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/buildium/browserify-builder-middleware/issues" | ||
}, | ||
"homepage": "https://github.com/buildium/browserify-builder-middleware#readme", | ||
"peerDependencies": { | ||
"browserify-builder": "^1.0.1", | ||
"watchify-middleware": "^1.6.0" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.13.1" | ||
} | ||
} |