-
-
Notifications
You must be signed in to change notification settings - Fork 376
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
055b651
Remove an unused variable
wuct b758720
Support for options.serverSideRender
wuct 4b77112
Merge pull request #1 from wuct/support-ssr
wuct cd0c024
Merge branch 'master' of https://github.com/webpack/webpack-dev-middl…
wuct 9e4f0e2
Use res.locals instead
wuct d614848
Lint
wuct e7ca967
Merge branch 'master' of https://github.com/webpack/webpack-dev-middl…
wuct c8b7ba7
Add server-sider rendering part to README
wuct File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -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() { | ||
|
@@ -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; | ||
|
||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build fails because of this; it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))) | ||
|
@@ -225,7 +236,7 @@ module.exports = function(compiler, options) { | |
} | ||
} | ||
} catch(e) { | ||
return next(); | ||
return goNext(); | ||
} | ||
|
||
// server content | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.