Skip to content

Commit d5fbe4b

Browse files
Fix aspnet-webpack package
1 parent 590574a commit d5fbe4b

5 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Helpers for using Webpack in ASP.NET projects. Works in conjunction with the Microsoft.AspNet.SpaServices NuGet package.",
55
"main": "index.js",
66
"scripts": {

src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack/src/DeepClone.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ExternalsPlugin from 'webpack-externals-plugin';
88
import requireFromString from 'require-from-string';
99
import MemoryFS from 'memory-fs';
1010
import * as webpack from 'webpack';
11-
import { deepClone } from './DeepClone';
11+
import { requireNewCopy } from './RequireNewCopy';
1212

1313
// Ensure we only go through the compile process once per [config, module] pair
1414
const loadViaWebpackPromisesCache: { [key: string]: any } = {};
@@ -32,7 +32,7 @@ export function loadViaWebpack<T>(webpackConfigPath: string, modulePath: string,
3232
function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string) {
3333
return new Promise<T>((resolve, reject) => {
3434
// Load the Webpack config and make alterations needed for loading the output into Node
35-
const webpackConfig: webpack.Configuration = deepClone(require(webpackConfigPath));
35+
const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath);
3636
webpackConfig.entry = modulePath;
3737
webpackConfig.target = 'node';
3838
webpackConfig.output = { path: '/', filename: 'webpack-output.js', libraryTarget: 'commonjs' };
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export function requireNewCopy(moduleNameOrPath: string): any {
2+
// Store a reference to whatever's in the 'require' cache,
3+
// so we don't permanently destroy it, and then ensure there's
4+
// no cache entry for this module
5+
const resolvedModule = require.resolve(moduleNameOrPath);
6+
const wasCached = resolvedModule in require.cache;
7+
let cachedInstance;
8+
if (wasCached) {
9+
cachedInstance = require.cache[resolvedModule];
10+
delete require.cache[resolvedModule];
11+
}
12+
13+
try {
14+
// Return a new copy
15+
return require(resolvedModule);
16+
} finally {
17+
// Restore the cached entry, if any
18+
if (wasCached) {
19+
require.cache[resolvedModule] = cachedInstance;
20+
}
21+
}
22+
}

src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as express from 'express';
22
import * as webpack from 'webpack';
3-
import { deepClone } from './DeepClone';
3+
import { requireNewCopy } from './RequireNewCopy';
44

55
export interface CreateDevServerCallback {
66
(error: any, result: { Port: number, PublicPath: string }): void;
@@ -20,7 +20,7 @@ interface DevServerOptions {
2020

2121
export function createWebpackDevServer(callback: CreateDevServerCallback, optionsJson: string) {
2222
const options: CreateDevServerOptions = JSON.parse(optionsJson);
23-
const webpackConfig: webpack.Configuration = deepClone(require(options.webpackConfigPath));
23+
const webpackConfig: webpack.Configuration = requireNewCopy(options.webpackConfigPath);
2424
const publicPath = (webpackConfig.output.publicPath || '').trim();
2525
if (!publicPath) {
2626
callback('To use the Webpack dev server, you must specify a value for \'publicPath\' on the \'output\' section of your webpack.config.', null);

0 commit comments

Comments
 (0)