web: Remove `config.publicPaths`
This simplifies the `publicPath` function and makes it useable inside `fetchRuffle`. Assuming `publicPaths` isn't used anywhere, this shouldn't be harmless.
This commit is contained in:
parent
c2fcc03c35
commit
28a155a099
|
@ -9,15 +9,7 @@ import { BaseLoadOptions } from "./load-options";
|
||||||
*/
|
*/
|
||||||
export interface Config extends BaseLoadOptions {
|
export interface Config extends BaseLoadOptions {
|
||||||
/**
|
/**
|
||||||
* A map of public paths from source name to URL.
|
* The URL at which Ruffle can load its extra files (i.e. `.wasm`).
|
||||||
*/
|
|
||||||
publicPaths?: Record<string, string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The URL at which Ruffle can load its extra files (ie `.wasm`).
|
|
||||||
*
|
|
||||||
* [publicPaths] is consulted first for a source-specific URL,
|
|
||||||
* with this field being a fallback.
|
|
||||||
*/
|
*/
|
||||||
publicPath?: string;
|
publicPath?: string;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { Config } from "./config";
|
||||||
|
|
||||||
let isExtension: boolean;
|
let isExtension: boolean;
|
||||||
const globalConfig: Config = window.RufflePlayer?.config ?? {};
|
const globalConfig: Config = window.RufflePlayer?.config ?? {};
|
||||||
const jsScriptUrl = publicPath(globalConfig, "ruffle.js") + "ruffle.js";
|
const jsScriptUrl = publicPath(globalConfig) + "ruffle.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polyfill native Flash elements with Ruffle equivalents.
|
* Polyfill native Flash elements with Ruffle equivalents.
|
||||||
|
|
|
@ -4,31 +4,22 @@ import { Config } from "./config";
|
||||||
* Attempt to discover the public path of the current Ruffle source. This can
|
* Attempt to discover the public path of the current Ruffle source. This can
|
||||||
* be used to configure Webpack.
|
* be used to configure Webpack.
|
||||||
*
|
*
|
||||||
* We have several points of configuration for how the Ruffle public path can
|
* A global public path can be specified for all sources using the RufflePlayer
|
||||||
* be determined:
|
* config:
|
||||||
*
|
*
|
||||||
* 1. The public path can be specified on a per-source basis using the
|
* ```js
|
||||||
* RufflePlayer config, for example:
|
* window.RufflePlayer.config.publicPath = "/dist/";
|
||||||
* `window.RufflePlayer.config.publicPaths.local = "/dist/";`
|
* ```
|
||||||
* 2. A global public path can be specified for all sources, also in config.
|
*
|
||||||
* `window.RufflePlayer.config.publicPath = "/dist/";`
|
* If no such config is specified, then the parent path of where this script is
|
||||||
* 3. If there is absolutely no configuration that yields a public path then we
|
* hosted is assumed, which should be the correct default in most cases.
|
||||||
* return the parent path of where this script is hosted, which should be
|
|
||||||
* the correct default in most cases.
|
|
||||||
*
|
*
|
||||||
* @param config The `window.RufflePlayer.config` object.
|
* @param config The `window.RufflePlayer.config` object.
|
||||||
* @param source_name The name of the source.
|
|
||||||
* @returns The public path for the given source.
|
* @returns The public path for the given source.
|
||||||
*/
|
*/
|
||||||
export function publicPath(config: Config, source_name: string): string {
|
export function publicPath(config: Config): string {
|
||||||
let path = "";
|
let path = "";
|
||||||
if (
|
if (config !== undefined && config.publicPath !== undefined) {
|
||||||
config !== undefined &&
|
|
||||||
config.publicPaths !== undefined &&
|
|
||||||
config.publicPaths[source_name] !== undefined
|
|
||||||
) {
|
|
||||||
path = config.publicPaths[source_name];
|
|
||||||
} else if (config !== undefined && config.publicPath !== undefined) {
|
|
||||||
path = config.publicPath;
|
path = config.publicPath;
|
||||||
} else if (
|
} else if (
|
||||||
document.currentScript !== undefined &&
|
document.currentScript !== undefined &&
|
||||||
|
@ -44,7 +35,7 @@ export function publicPath(config: Config, source_name: string): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Webpack expects the paths to end with a /.
|
// Webpack expects the paths to end with a slash.
|
||||||
if (path !== "" && !path.endsWith("/")) {
|
if (path !== "" && !path.endsWith("/")) {
|
||||||
path += "/";
|
path += "/";
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ const api = PublicAPI.negotiate(
|
||||||
new SourceAPI("local")
|
new SourceAPI("local")
|
||||||
);
|
);
|
||||||
window.RufflePlayer = api;
|
window.RufflePlayer = api;
|
||||||
__webpack_public_path__ = publicPath(api.config, "local");
|
__webpack_public_path__ = publicPath(api.config);
|
||||||
const ruffle = api.newest()!;
|
const ruffle = api.newest()!;
|
||||||
|
|
||||||
// Default config used by the player.
|
// Default config used by the player.
|
||||||
|
|
|
@ -6,7 +6,7 @@ const api = PublicAPI.negotiate(
|
||||||
new SourceAPI("extension")
|
new SourceAPI("extension")
|
||||||
);
|
);
|
||||||
window.RufflePlayer = api;
|
window.RufflePlayer = api;
|
||||||
__webpack_public_path__ = publicPath(api.config, "extension");
|
__webpack_public_path__ = publicPath(api.config);
|
||||||
|
|
||||||
let uniqueMessageSuffix: string | null = null;
|
let uniqueMessageSuffix: string | null = null;
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -5,4 +5,4 @@ window.RufflePlayer = PublicAPI.negotiate(
|
||||||
"local",
|
"local",
|
||||||
new SourceAPI("local")
|
new SourceAPI("local")
|
||||||
);
|
);
|
||||||
__webpack_public_path__ = publicPath(window.RufflePlayer.config, "local");
|
__webpack_public_path__ = publicPath(window.RufflePlayer.config);
|
||||||
|
|
Loading…
Reference in New Issue