webpack-hot-server-middleware
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "webpack-hot-server-middleware", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Hot updates Webpack bundles on the server", | ||
@@ -9,2 +9,7 @@ "main": "src/", | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"setupTestFrameworkScriptFile": "<rootDir>/test/support/setup.js", | ||
"preprocessorIgnorePatterns": ["/node_modules/", "<rootDir>/src"] | ||
}, | ||
"repository": { | ||
@@ -21,3 +26,3 @@ "type": "git", | ||
"debug": "^2.2.0", | ||
"require-from-string": "^1.2.0", | ||
"require-from-string": "^1.2.1", | ||
"source-map-support": "^0.4.2" | ||
@@ -27,3 +32,13 @@ }, | ||
"webpack": "*" | ||
}, | ||
"devDependencies": { | ||
"babel-jest": "^15.0.0", | ||
"babel-loader": "^6.2.5", | ||
"babel-preset-es2015": "^6.16.0", | ||
"express": "^4.14.0", | ||
"jest": "^15.1.1", | ||
"supertest": "^2.0.0", | ||
"webpack": "^1.13.2", | ||
"webpack-dev-middleware": "^1.8.3" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Webpack Hot Server Middleware | ||
# Webpack Hot Server Middleware [![Build Status](https://travis-ci.org/60frames/webpack-hot-server-middleware.svg?branch=master)](https://travis-ci.org/60frames/webpack-hot-server-middleware) [![npm version](https://badge.fury.io/js/webpack-hot-server-middleware.svg)](https://badge.fury.io/js/wwebpack-hot-server-middleware) | ||
@@ -115,3 +115,3 @@ ## What? | ||
An example setup can be found in the [example](example) directory. | ||
A simple example can be found in the [example](example) directory and a more real world example can be seen in the [60fram.es boilerplate](https://github.com/60frames/react-boilerplate) | ||
@@ -118,0 +118,0 @@ ## License |
@@ -25,4 +25,4 @@ 'use strict'; | ||
function getChunkFilename(stats, outputPath, chunkName) { | ||
const assetsByChunkName = stats.toJson().assetsByChunkName; | ||
function getFilename(serverStats, outputPath, chunkName) { | ||
const assetsByChunkName = serverStats.toJson().assetsByChunkName; | ||
let filename = assetsByChunkName[chunkName] || ''; | ||
@@ -38,2 +38,20 @@ // If source maps are generated `assetsByChunkName.main` | ||
function getServerRenderer(filename, buffer, clientStats) { | ||
const errMessage = `The 'server' compiler must export a function in the form of \`(stats) => (req, res, next) => void 0\``; | ||
let serverRenderer = interopRequireDefault( | ||
requireFromString(buffer.toString(), filename) | ||
); | ||
if (typeof serverRenderer !== 'function') { | ||
throw new Error(errMessage); | ||
} | ||
serverRenderer = serverRenderer(clientStats.toJson()); | ||
if (typeof serverRenderer !== 'function') { | ||
throw new Error(errMessage); | ||
} | ||
return serverRenderer; | ||
} | ||
function installSourceMapSupport(fs) { | ||
@@ -51,3 +69,3 @@ sourceMapSupport.install({ | ||
}; | ||
} catch(e) { | ||
} catch(ex) { | ||
// Doesn't exist | ||
@@ -72,4 +90,4 @@ } | ||
if (!multiCompiler instanceof MultiCompiler) { | ||
throw new Error('Expected webpack compiler to contain both a `client` and `server` config'); | ||
if (!(multiCompiler instanceof MultiCompiler)) { | ||
throw new Error(`Expected webpack compiler to contain both a 'client' and 'server' config`); | ||
} | ||
@@ -81,6 +99,6 @@ | ||
if (!serverCompiler) { | ||
throw new Error('Expected a webpack compiler named `server`'); | ||
throw new Error(`Expected a webpack compiler named 'server'`); | ||
} | ||
if (!clientCompiler) { | ||
throw new Error('Expected a webpack compiler named `client`'); | ||
throw new Error(`Expected a webpack compiler named 'client'`); | ||
} | ||
@@ -97,2 +115,3 @@ | ||
multiCompiler.plugin('done', multiStats => { | ||
error = false; | ||
const clientStats = findStats(multiStats, 'client'); | ||
@@ -105,12 +124,9 @@ const serverStats = findStats(multiStats, 'server'); | ||
} | ||
error = false; | ||
const filename = getChunkFilename(serverStats, outputPath, options.chunkName); | ||
const filename = getFilename(serverStats, outputPath, options.chunkName); | ||
const buffer = outputFs.readFileSync(filename); | ||
try { | ||
const data = outputFs.readFileSync(filename); | ||
serverRenderer = interopRequireDefault( | ||
requireFromString(data.toString(), filename) | ||
)(clientStats.toJson()); | ||
} catch (e) { | ||
debug(e); | ||
error = e; | ||
serverRenderer = getServerRenderer(filename, buffer, clientStats); | ||
} catch (ex) { | ||
debug(ex); | ||
error = ex; | ||
} | ||
@@ -117,0 +133,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
26364
43
603
8
1
Updatedrequire-from-string@^1.2.1