Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var path = require("path");
var MemoryFileSystem = require("memory-fs");
var mime = require("mime");

Expand Down Expand Up @@ -124,15 +125,23 @@ module.exports = function(compiler, options) {
function webpackDevMiddleware(req, res, next) {
var filename = getFilenameFromUrl(req.url);
if (filename === false) return next();

// in lazy mode, rebuild on bundle request
if(options.lazy && filename === pathJoin(compiler.outputPath, options.filename))
rebuild();
// delay the request until we have a vaild bundle
ready(function() {
try {
var stat = fs.statSync(filename);
if(!stat.isFile()) throw "next";
if(!stat.isFile()) {
if (stat.isDirectory()) {
filename = path.join(filename, "index.html");
stat = fs.statSync(filename);
if(!stat.isFile()) throw "next";
} else {
throw "next";
}
}
} catch(e) {
return next();
}
Expand Down