aspnet-webpack
Advanced tools
Comparing version 1.0.24 to 1.0.25
{ | ||
"name": "aspnet-webpack", | ||
"version": "1.0.24", | ||
"version": "1.0.25", | ||
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,2 +22,3 @@ import * as connect from 'connect'; | ||
suppliedOptions: DevServerOptions; | ||
hotModuleReplacementEndpointUrl: string; | ||
} | ||
@@ -32,3 +33,3 @@ | ||
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean, hmrEndpoint: string) { | ||
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean, hmrClientEndpoint: string, hmrServerEndpoint: string) { | ||
// Build the final Webpack config based on supplied options | ||
@@ -49,3 +50,3 @@ if (enableHotModuleReplacement) { | ||
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client'; | ||
const webpackHotMiddlewareOptions = `?path=` + encodeURIComponent(hmrEndpoint); | ||
const webpackHotMiddlewareOptions = `?path=` + encodeURIComponent(hmrClientEndpoint); | ||
if (typeof entryPoints[entryPointName] === 'string') { | ||
@@ -123,3 +124,5 @@ entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions, entryPoints[entryPointName]]; | ||
} | ||
app.use(webpackHotMiddlewareModule(compiler)); | ||
app.use(webpackHotMiddlewareModule(compiler, { | ||
path: hmrServerEndpoint | ||
})); | ||
} | ||
@@ -205,4 +208,12 @@ } | ||
const hmrEndpoint = `http://localhost:${listener.address().port}/__webpack_hmr`; | ||
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrEndpoint); | ||
// Newer versions of Microsoft.AspNetCore.SpaServices will explicitly pass an HMR endpoint URL | ||
// (because it's relative to the app's URL space root, which the client doesn't otherwise know). | ||
// For back-compatibility, fall back on connecting directly to the underlying HMR server (though | ||
// that won't work if the app is hosted on HTTPS because of the mixed-content rule, and we can't | ||
// run the HMR server itself on HTTPS because in general it has no valid cert). | ||
const hmrClientEndpoint = options.hotModuleReplacementEndpointUrl // The URL that we'll proxy (e.g., /__asp_webpack_hmr) | ||
|| `http://localhost:${listener.address().port}/__webpack_hmr`; // Fall back on absolute URL to bypass proxying | ||
const hmrServerEndpoint = options.hotModuleReplacementEndpointUrl | ||
|| '/__webpack_hmr'; // URL is relative to webpack dev server root | ||
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrClientEndpoint, hmrServerEndpoint); | ||
} | ||
@@ -209,0 +220,0 @@ }); |
@@ -8,3 +8,3 @@ "use strict"; | ||
var RequireNewCopy_1 = require('./RequireNewCopy'); | ||
function attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrEndpoint) { | ||
function attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrClientEndpoint, hmrServerEndpoint) { | ||
// Build the final Webpack config based on supplied options | ||
@@ -24,3 +24,3 @@ if (enableHotModuleReplacement) { | ||
var webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client'; | ||
var webpackHotMiddlewareOptions = "?path=" + encodeURIComponent(hmrEndpoint); | ||
var webpackHotMiddlewareOptions = "?path=" + encodeURIComponent(hmrClientEndpoint); | ||
if (typeof entryPoints_1[entryPointName] === 'string') { | ||
@@ -91,3 +91,5 @@ entryPoints_1[entryPointName] = [webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions, entryPoints_1[entryPointName]]; | ||
} | ||
app.use(webpackHotMiddlewareModule(compiler)); | ||
app.use(webpackHotMiddlewareModule(compiler, { | ||
path: hmrServerEndpoint | ||
})); | ||
} | ||
@@ -167,4 +169,12 @@ } | ||
normalizedPublicPaths_1.push(removeTrailingSlash(publicPath)); | ||
var hmrEndpoint = "http://localhost:" + listener.address().port + "/__webpack_hmr"; | ||
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrEndpoint); | ||
// Newer versions of Microsoft.AspNetCore.SpaServices will explicitly pass an HMR endpoint URL | ||
// (because it's relative to the app's URL space root, which the client doesn't otherwise know). | ||
// For back-compatibility, fall back on connecting directly to the underlying HMR server (though | ||
// that won't work if the app is hosted on HTTPS because of the mixed-content rule, and we can't | ||
// run the HMR server itself on HTTPS because in general it has no valid cert). | ||
var hmrClientEndpoint = options.hotModuleReplacementEndpointUrl // The URL that we'll proxy (e.g., /__asp_webpack_hmr) | ||
|| "http://localhost:" + listener.address().port + "/__webpack_hmr"; // Fall back on absolute URL to bypass proxying | ||
var hmrServerEndpoint = options.hotModuleReplacementEndpointUrl | ||
|| '/__webpack_hmr'; // URL is relative to webpack dev server root | ||
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrClientEndpoint, hmrServerEndpoint); | ||
} | ||
@@ -171,0 +181,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
48300
801