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:
@@ -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',
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user