mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
8138c83558
Plyr's defaults point at its CDN twice: the icon sprite for the controls is fetched over XHR, and on teardown the element is pointed at a blank clip there to abort the stream. connect-src and media-src both refuse that host, so the clip played but every button in the player was blank, and each close of the lightbox logged a blocked request and an uncaught XHR error. The sprite ships with the bundle now, served from this origin, which Plyr then references directly instead of loading it. plyr's exports field hides the file, so it goes through the same resolver alias the rtl-text plugin already needed. The teardown source is empty: that aborts the stream just the same, and the element is unmounted in the same tick. Refs #2341
40 lines
1.6 KiB
JavaScript
40 lines
1.6 KiB
JavaScript
import { createRequire } from 'node:module';
|
|
import path from 'node:path';
|
|
|
|
/**
|
|
* setRTLTextPlugin() takes the URL of a classic script that the GL worker pulls in
|
|
* with importScripts. mapbox-gl-rtl-text ships exactly that as
|
|
* dist/mapbox-gl-rtl-text.js, but its "exports" field publishes only the ESM/WASM
|
|
* entry, so the resolver refuses the subpath. Resolving the entry it does publish
|
|
* and stepping across to dist keeps this working wherever npm hoists the package.
|
|
*
|
|
* Shared by vite.config.js and vitest.config.ts: the build needs it to emit the
|
|
* asset, and the test run needs it because a lazily imported engine module reaches
|
|
* the same specifier.
|
|
*
|
|
* The pattern is a regex, not a string key: the import carries a `?url` suffix,
|
|
* which a string alias will not match. It is left unanchored on purpose so the
|
|
* query survives the rewrite and Vite still emits an asset URL.
|
|
*/
|
|
export const rtlTextAlias = {
|
|
find: /^@mapbox\/mapbox-gl-rtl-text\/dist\/mapbox-gl-rtl-text\.js/,
|
|
replacement: path.join(
|
|
path.dirname(createRequire(import.meta.url).resolve('@mapbox/mapbox-gl-rtl-text')),
|
|
'../dist/mapbox-gl-rtl-text.js',
|
|
),
|
|
};
|
|
|
|
/**
|
|
* Same shape for Plyr's icon sprite. The package publishes its JS and CSS entries
|
|
* and nothing else, so `plyr/dist/plyr.svg` is refused by the resolver although
|
|
* the file is right there. The player has to point at a copy on this origin
|
|
* (#2341): its default is the sprite on cdn.plyr.io, which the CSP refuses.
|
|
*/
|
|
export const plyrSpriteAlias = {
|
|
find: /^plyr\/dist\/plyr\.svg/,
|
|
replacement: path.join(
|
|
path.dirname(createRequire(import.meta.url).resolve('plyr')),
|
|
'plyr.svg',
|
|
),
|
|
};
|