webpack-dev-middleware
Advanced tools
Comparing version 0.7.4 to 0.8.0
@@ -9,15 +9,22 @@ /* | ||
// constructor for the middleware | ||
module.exports = function(context, module, options) { | ||
// get to options, we may have 2 function prototypes | ||
module.exports = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
// get options, we may have 2 function prototypes | ||
// (absoluteModule, options) and (context, module, options) | ||
var opt = options || module; | ||
var opt = args.pop(); | ||
var wpOpt = opt.webpack = opt.webpack || { | ||
watch: true, | ||
debug: true | ||
}; | ||
var context = null; | ||
if(args.length == 2) context = args[0]; | ||
// We do the stuff in memory, so don't write | ||
opt.noWrite = true; | ||
wpOpt.noWrite = true; | ||
// We need you own events to bind some stuff | ||
opt.events = opt.events || new (require("events").EventEmitter)(); | ||
wpOpt.events = wpOpt.events || new (require("events").EventEmitter)(); | ||
// Grap files from webpack | ||
opt.emitFile = function(filename, content) { | ||
wpOpt.emitFile = function(filename, content) { | ||
files[filename] = content; | ||
@@ -27,3 +34,3 @@ } | ||
// on bundle | ||
opt.events.on("bundle", function(stats) { | ||
wpOpt.events.on("bundle", function(stats) { | ||
// We are now on valid state | ||
@@ -37,15 +44,15 @@ state = true; | ||
// print webpack output | ||
var displayStats = !opt.middleware || !opt.middleware.quiet; | ||
var displayStats = !opt.quiet; | ||
if(displayStats && | ||
!(stats.errors && stats.errors.length > 0 || stats.warnings && stats.warnings.length > 0) && | ||
opt.middleware && opt.middleware.noInfo) | ||
opt.noInfo) | ||
displayStats = false; | ||
if(displayStats) { | ||
console.log(formatOutput(stats, { | ||
context: opt.context || context || process.cwd(), | ||
colors: true, | ||
verbose: opt.verbose | ||
context: opt.context || wpOpt.context || context || process.cwd(), | ||
colors: opt.colors !== false, | ||
verbose: opt.verbose || false | ||
})); | ||
} | ||
if(!opt.middleware || (!opt.middleware.noInfo && !opt.middleware.quiet)) | ||
if(!opt.noInfo && !opt.quiet) | ||
console.info("webpack: bundle is now VALID."); | ||
@@ -63,4 +70,4 @@ | ||
// on bundle invalidated | ||
opt.events.on("bundle-invalid", function() { | ||
if(state && (!opt.middleware || (!opt.middleware.noInfo && !opt.middleware.quiet))) | ||
wpOpt.events.on("bundle-invalid", function() { | ||
if(state && (!opt.noInfo && !opt.quiet)) | ||
console.info("webpack: bundle is now invalid."); | ||
@@ -72,3 +79,3 @@ // We are now in invalid state | ||
// start webpack | ||
var args = Array.prototype.slice.call(arguments); | ||
args.push(wpOpt); | ||
args.push(function(err) { | ||
@@ -91,3 +98,3 @@ if(err) throw err; | ||
if(state) return fn(); | ||
if(!opt.middleware || (!opt.middleware.noInfo && !opt.middleware.quiet)) | ||
if(!opt.noInfo && !opt.quiet) | ||
console.log("webpack: wait until bundle finished: " + req.url); | ||
@@ -100,3 +107,3 @@ callbacks.push(fn); | ||
// publicPrefix ist the folder our bundle should be in | ||
var localPrefix = opt.publicPrefix || ""; | ||
var localPrefix = wpOpt.publicPrefix || ""; | ||
if(/^https?:\/\//.test(localPrefix)) { | ||
@@ -118,2 +125,7 @@ localPrefix = localPrefix.replace(/^https?:\/\/[^\/]+\//, ""); | ||
res.setHeader("Content-Type", "text/javascript"); // No warning in Chrome. | ||
if(opt.headers) { | ||
for(var name in opt.headers) { | ||
res.setHeader(name, opt.headers[name]); | ||
} | ||
} | ||
res.end(content); | ||
@@ -120,0 +132,0 @@ }, req); |
{ | ||
"name": "webpack-dev-middleware", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "Offers a dev middleware for webpack, which arguments a live bundle to a directory", | ||
"dependencies": { | ||
"webpack": "0.7.x" | ||
"webpack": "0.8.x" | ||
}, | ||
@@ -9,0 +9,0 @@ "licenses": [ |
@@ -24,32 +24,42 @@ # webpack-dev-middleware | ||
Use the `webpackMiddleware` function like the webpack function, but without callback. | ||
Example usage: | ||
``` javascript | ||
app.use(webpackMiddleware(__dirname, "./lib/file", { | ||
watch: true, | ||
debug: true, | ||
publicPrefix: "http://localhost:8080/assets/", | ||
output: "bundle.js", | ||
outputPostfix: ".bundle.js", | ||
// ... more webpack config options | ||
})); | ||
``` | ||
app.use(webpackMiddleware(/* context = */ __dirname, /* module = */ "./lib/file", { | ||
// all options optional, but options object not | ||
### options.watch = true | ||
noInfo: false, | ||
// display no info to console (only warnings and errors) | ||
This is not required, but recommendated to get the best out of the middleware. | ||
quiet: false, | ||
// display nothing to the console | ||
### options.publicPrefix | ||
colors: true, | ||
// colorful webpack stats | ||
The prefix for request that should be handled. | ||
verbose: false, | ||
// verbose webpack stats | ||
### options.output, options.outputPostfix | ||
context: "/home/user", | ||
// context for webpack stats | ||
The filename for the bundle. | ||
headers: { "X-Custom-Header": "yes" }, | ||
// custom headers | ||
### options.verbose | ||
// webpack options | ||
webpack: { | ||
watch: true, | ||
// This is not required, but recommendated to get the best out of the middleware. | ||
Verbose output of the statistics. | ||
publicPrefix: "http://localhost:8080/assets/", | ||
// The prefix for request that should be handled. | ||
### All other options like webpack | ||
output: "bundle.js", | ||
// The filename for the bundle. | ||
// ... more webpack config options | ||
debug: true, | ||
outputPostfix: ".bundle.js", | ||
} | ||
})); | ||
``` |
5970
111
65
+ Addedamdefine@1.0.1(transitive)
+ Addedbuffer-equal@0.0.2(transitive)
+ Addedbundle-loader@0.3.0(transitive)
+ Addedclone@0.0.7(transitive)
+ Addedenhanced-require@0.4.2(transitive)
+ Addedenhanced-resolve@0.4.12(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedscript-loader@0.3.1(transitive)
+ Addedsource-map@0.1.43(transitive)
+ Addeduglify-js@2.2.5(transitive)
+ Addedval-loader@0.2.0(transitive)
+ Addedwebpack@0.8.3(transitive)
- Removedbundle-loader@0.2.0(transitive)
- Removedenhanced-require@0.3.1(transitive)
- Removedenhanced-resolve@0.2.90.3.1(transitive)
- Removedscript-loader@0.2.1(transitive)
- Removeduglify-js@1.2.6(transitive)
- Removedval-loader@0.1.2(transitive)
- Removedwebpack@0.7.17(transitive)
Updatedwebpack@0.8.x