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 server-side rendering #118

Merged
merged 8 commits into from
Sep 8, 2016
Merged
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're at it, could you rewrite this to function goNext? that's more consistent with the above function.

if (!options.serverSideRender) return next()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build fails because of this; it should be if(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

ready(function() {
res.locals.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