Socket
Socket
Sign inDemoInstall

webpack-hot-server-middleware

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-hot-server-middleware - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

5

package.json
{
"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": {

10

README.md

@@ -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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc