webpack-hot-server-middleware
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "webpack-hot-server-middleware", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Hot updates Webpack bundles on the server", | ||
@@ -20,3 +20,4 @@ "main": "src/", | ||
"debug": "^2.2.0", | ||
"require-from-string": "^1.2.0" | ||
"require-from-string": "^1.2.0", | ||
"source-map-support": "^0.4.2" | ||
}, | ||
@@ -23,0 +24,0 @@ "peerDependencies": { |
@@ -13,3 +13,3 @@ # Webpack Hot Server Middleware | ||
``` | ||
```js | ||
// client.js | ||
@@ -25,3 +25,3 @@ | ||
``` | ||
```js | ||
// server.js | ||
@@ -54,3 +54,3 @@ | ||
``` | ||
```js | ||
const express = require('express'); | ||
@@ -76,3 +76,3 @@ const universalRenderer = require('./dist/server'); | ||
``` | ||
```js | ||
// webpack.config.js | ||
@@ -100,3 +100,3 @@ | ||
``` | ||
```js | ||
const express = require('express'); | ||
@@ -103,0 +103,0 @@ const webpack = require('webpack'); |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const MultiCompiler = require('webpack/lib/MultiCompiler'); | ||
const sourceMapSupport = require('source-map-support'); | ||
@@ -21,2 +22,33 @@ const DEFAULTS = { | ||
function getChunkFilename(stats, outputPath, chunkName) { | ||
const assetsByChunkName = stats.toJson().assetsByChunkName; | ||
let filename = assetsByChunkName[chunkName] || ''; | ||
// If source maps are generated `assetsByChunkName.main` | ||
// will be an array of filenames. | ||
return path.join( | ||
outputPath, | ||
Array.isArray(filename) ? | ||
filename.find(asset => /\.js$/.test(asset)) : filename | ||
); | ||
} | ||
function installSourceMapSupport(fs) { | ||
sourceMapSupport.install({ | ||
// NOTE: If https://github.com/evanw/node-source-map-support/pull/149 | ||
// lands we can be less aggressive and explicitly invalidate the source | ||
// map cache when Webpack recompiles. | ||
emptyCacheBetweenOperations: true, | ||
retrieveSourceMap(source) { | ||
try { | ||
return { | ||
url: source, | ||
map: fs.readFileSync(`${source}.map`).toString() | ||
}; | ||
} catch(e) { | ||
// Doesn't exist | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -52,2 +84,4 @@ * Passes the request to the most up to date 'server' bundle. | ||
installSourceMapSupport(outputFs); | ||
let universalRenderer; | ||
@@ -65,12 +99,8 @@ let error = false; | ||
error = false; | ||
const filename = getChunkFilename(serverStats, outputPath, options.chunkName); | ||
try { | ||
const data = outputFs.readFileSync( | ||
path.join( | ||
outputPath, | ||
serverStats.toJson().assetsByChunkName[options.chunkName] | ||
) | ||
); | ||
universalRenderer = requireFromString(data.toString()).default(clientStats.toJson()); | ||
const data = outputFs.readFileSync(filename); | ||
universalRenderer = requireFromString(data.toString(), filename).default(clientStats.toJson()); | ||
} catch (e) { | ||
debug(`Error: ${e}`); | ||
debug(e); | ||
error = e; | ||
@@ -77,0 +107,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
9729
98
4
+ Addedsource-map-support@^0.4.2
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-support@0.4.18(transitive)