1
0

Always load Ruffle from CDN and add it as a dependency

This commit has a long story behind it.
Removes Ruffle from /scripts/ and instead always loads the installed version from unpkg, Ruffle's preferred CDN.
This requires having unpkg in the CORS rules.
Ruffle is also loaded from the CDN in dev mode. To help with this an externalPackages array has been added to the vite dev config.

Co-authored-by: Julia Johannesen <julia@insertdomain.name>
This commit is contained in:
CenTdemeern1
2024-10-15 21:11:55 +02:00
parent f137101b90
commit 051073a046
18 changed files with 171 additions and 760 deletions
+28 -1
View File
@@ -2,7 +2,7 @@ import dns from 'dns';
import { readFile } from 'node:fs/promises';
import type { IncomingMessage } from 'node:http';
import { defineConfig } from 'vite';
import type { UserConfig } from 'vite';
import type { PluginOption, UserConfig } from 'vite';
import * as yaml from 'js-yaml';
import locales from '../../locales/index.js';
import { getConfig } from './vite.config.js';
@@ -25,6 +25,20 @@ function varyHandler(req: IncomingMessage) {
return '/index.html';
}
const externalPackages = [
// sharkey: Used for SkFlashPlayer, has large wasm files so it's loaded via Ruffle's preferred CDN
{
name: 'ruffle',
match: /^@ruffle-rs\/ruffle\/?(?<file>.*)$/,
path(id: string, pattern: RegExp): string {
const match = pattern.exec(id)?.groups;
return match
? `https://unpkg.com/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/${match['file']}`
: id;
},
},
]
const devConfig: UserConfig = {
// 基本の設定は vite.config.js から引き継ぐ
...defaultConfig,
@@ -88,6 +102,19 @@ const devConfig: UserConfig = {
...defaultConfig.build,
rollupOptions: {
...defaultConfig.build?.rollupOptions,
external: externalPackages.map(p => p.match),
output: {
...defaultConfig.build?.rollupOptions?.output,
paths(id) {
for (const p of externalPackages) {
if (p.match.test(id)) {
return p.path(id, p.match);
}
}
return id;
},
},
input: 'index.html',
},
},