mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 10:08:57 +00:00
Make aspnet-webpack and SpaServices both back-compatible with older versions of the other, in case people don't upgrade both at the same time
This commit is contained in:
@@ -65,11 +65,11 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
nodeServices.InvokeExportAsync<WebpackDevServerInfo>(nodeScript.FileName, "createWebpackDevServer",
|
nodeServices.InvokeExportAsync<WebpackDevServerInfo>(nodeScript.FileName, "createWebpackDevServer",
|
||||||
JsonConvert.SerializeObject(devServerOptions)).Result;
|
JsonConvert.SerializeObject(devServerOptions)).Result;
|
||||||
|
|
||||||
// Older versions of aspnet-webpack just returned a single 'publicPath', but now we support multiple
|
// If we're talking to an older version of aspnet-webpack, it will return only a single PublicPath,
|
||||||
|
// not an array of PublicPaths. Handle that scenario.
|
||||||
if (devServerInfo.PublicPaths == null)
|
if (devServerInfo.PublicPaths == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
devServerInfo.PublicPaths = new[] { devServerInfo.PublicPath };
|
||||||
"To enable Webpack dev middleware, you must update to a newer version of the aspnet-webpack NPM package.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy the corresponding requests through ASP.NET and into the Node listener
|
// Proxy the corresponding requests through ASP.NET and into the Node listener
|
||||||
@@ -107,6 +107,10 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
{
|
{
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
public string[] PublicPaths { get; set; }
|
public string[] PublicPaths { get; set; }
|
||||||
|
|
||||||
|
// For back-compatibility with older versions of aspnet-webpack, in the case where your webpack
|
||||||
|
// configuration contains exactly one config entry. This will be removed soon.
|
||||||
|
public string PublicPath { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore CS0649
|
#pragma warning restore CS0649
|
||||||
|
|||||||
@@ -3,13 +3,18 @@ import * as webpack from 'webpack';
|
|||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
import { requireNewCopy } from './RequireNewCopy';
|
import { requireNewCopy } from './RequireNewCopy';
|
||||||
|
|
||||||
|
export type CreateDevServerResult = {
|
||||||
|
Port: number,
|
||||||
|
PublicPaths: string[],
|
||||||
|
PublicPath: string // For backward compatibility with older verions of Microsoft.AspNetCore.SpaServices. Will be removed soon.
|
||||||
|
};
|
||||||
|
|
||||||
export interface CreateDevServerCallback {
|
export interface CreateDevServerCallback {
|
||||||
(error: any, result: { Port: number, PublicPaths: string[] }): void;
|
(error: any, result: CreateDevServerResult): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are the options passed by WebpackDevMiddleware.cs
|
// These are the options passed by WebpackDevMiddleware.cs
|
||||||
interface CreateDevServerOptions {
|
interface CreateDevServerOptions {
|
||||||
understandsMultiplePublicPaths: boolean; // For checking that the NuGet package is recent enough. Can be removed when we no longer need back-compatibility.
|
|
||||||
webpackConfigPath: string;
|
webpackConfigPath: string;
|
||||||
suppliedOptions: DevServerOptions;
|
suppliedOptions: DevServerOptions;
|
||||||
}
|
}
|
||||||
@@ -89,11 +94,6 @@ function beginWebpackWatcher(webpackConfig: webpack.Configuration) {
|
|||||||
export function createWebpackDevServer(callback: CreateDevServerCallback, optionsJson: string) {
|
export function createWebpackDevServer(callback: CreateDevServerCallback, optionsJson: string) {
|
||||||
const options: CreateDevServerOptions = JSON.parse(optionsJson);
|
const options: CreateDevServerOptions = JSON.parse(optionsJson);
|
||||||
|
|
||||||
if (!options.understandsMultiplePublicPaths) {
|
|
||||||
callback('To use Webpack dev server, you must update to a newer version of the Microsoft.AspNetCore.SpaServices package', null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the webpack config's export, and normalize it into the more general 'array of configs' format
|
// Read the webpack config's export, and normalize it into the more general 'array of configs' format
|
||||||
let webpackConfigArray: webpack.Configuration[] = requireNewCopy(options.webpackConfigPath);
|
let webpackConfigArray: webpack.Configuration[] = requireNewCopy(options.webpackConfigPath);
|
||||||
if (!(webpackConfigArray instanceof Array)) {
|
if (!(webpackConfigArray instanceof Array)) {
|
||||||
@@ -137,7 +137,11 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
|
|||||||
// Tell the ASP.NET app what addresses we're listening on, so that it can proxy requests here
|
// Tell the ASP.NET app what addresses we're listening on, so that it can proxy requests here
|
||||||
callback(null, {
|
callback(null, {
|
||||||
Port: listener.address().port,
|
Port: listener.address().port,
|
||||||
PublicPaths: normalizedPublicPaths
|
PublicPaths: normalizedPublicPaths,
|
||||||
|
|
||||||
|
// For back-compatibility with older versions of Microsoft.AspNetCore.SpaServices, in the case where
|
||||||
|
// you have exactly one webpackConfigArray entry. This will be removed soon.
|
||||||
|
PublicPath: normalizedPublicPaths[0]
|
||||||
});
|
});
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
callback(ex.stack, null);
|
callback(ex.stack, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user