Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for options.serverSideRender #1

Merged
merged 1 commit into from
Sep 2, 2016
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
15 changes: 13 additions & 2 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = function(compiler, options) {
compiler.plugin("done", function(stats) {
// We are now on valid state
state = true;
webpackStats = stats
// Do the stuff in nextTick, because bundle may be invalidated
// if a change happened while compiling
process.nextTick(function() {
Expand Down Expand Up @@ -108,6 +109,8 @@ module.exports = function(compiler, options) {
// the state, false: bundle invalid, true: bundle valid
var state = false;

var webpackStats;

// in lazy mode, rebuild automatically
var forceRebuild = false;

Expand Down Expand Up @@ -194,8 +197,16 @@ module.exports = function(compiler, options) {

// The middleware function
function webpackDevMiddleware(req, res, next) {
var goNext = function() {
if (!options.serverSideRender) return next()
ready(function() {
res.webpackStats = webpackStats
next()
}, req)
}

var filename = getFilenameFromUrl(req.url);
if(filename === false) return next();
if(filename === false) return goNext();

// in lazy mode, rebuild on bundle request
if(options.lazy && (!options.filename || options.filename.test(filename)))
Expand Down Expand Up @@ -225,7 +236,7 @@ module.exports = function(compiler, options) {
}
}
} catch(e) {
return next();
return goNext();
}

// server content
Expand Down