webpack-hot-server-middleware
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "webpack-hot-server-middleware", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Hot updates Webpack bundles on the server", | ||
@@ -5,0 +5,0 @@ "main": "src/", |
@@ -19,3 +19,3 @@ # Webpack Hot Server Middleware | ||
ReactDOM.render(<App />, document.getElementById('#root')); | ||
ReactDOM.render(<App />, document.getElementById('root')); | ||
``` | ||
@@ -31,3 +31,3 @@ | ||
export default function universalRenderer() { | ||
export default function serverRenderer() { | ||
return (req, res, next) => { | ||
@@ -44,3 +44,3 @@ res.status(200).send(` | ||
</div> | ||
<script src="/bundle.js"></script> | ||
<script src="/client.js"></script> | ||
</body> | ||
@@ -57,6 +57,6 @@ </html> | ||
const express = require('express'); | ||
const universalRenderer = require('./dist/server'); | ||
const serverRenderer = require('./dist/server'); | ||
const app = express(); | ||
app.use(universalRenderer()); | ||
app.use(serverRenderer()); | ||
app.listen(6060); | ||
@@ -86,4 +86,3 @@ ``` | ||
... | ||
}, | ||
{ | ||
}, { | ||
name: 'server', | ||
@@ -113,4 +112,14 @@ target: 'node', | ||
app.use(webpackHotServerMiddleware(compiler)); | ||
app.listen(6060); | ||
``` | ||
Now whenever Webpack rebuilds the new bundle will be used both client and *server* side. | ||
### Example | ||
An example setup can be found in the [example](example) directory. | ||
## License | ||
MIT |
@@ -13,2 +13,6 @@ 'use strict'; | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj.default : obj; | ||
} | ||
function findCompiler(multiCompiler, name) { | ||
@@ -85,3 +89,3 @@ return multiCompiler.compilers.find(compiler => compiler.name === name); | ||
let universalRenderer; | ||
let serverRenderer; | ||
let error = false; | ||
@@ -101,3 +105,5 @@ | ||
const data = outputFs.readFileSync(filename); | ||
universalRenderer = requireFromString(data.toString(), filename).default(clientStats.toJson()); | ||
serverRenderer = interopRequireDefault( | ||
requireFromString(data.toString(), filename) | ||
)(clientStats.toJson()); | ||
} catch (e) { | ||
@@ -114,3 +120,3 @@ debug(e); | ||
} | ||
universalRenderer(req, res, next); | ||
serverRenderer(req, res, next); | ||
}; | ||
@@ -117,0 +123,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12536
12
168
120