mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
support flash
This commit is contained in:
+45
-1
@@ -2,12 +2,56 @@ import { defineConfig } from 'vitest/config'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
import { svelteTesting } from '@testing-library/svelte/vite'
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
const RUFFLE_DIRECTORY = fileURLToPath(
|
||||
new URL('./node_modules/@ruffle-rs/ruffle/', import.meta.url),
|
||||
)
|
||||
const RUFFLE_ASSET_PATTERN = /^(?:ruffle\.js|core\.ruffle\..+\.js|.+\.wasm|LICENSE_(?:MIT|APACHE))$/
|
||||
|
||||
/** Serve and emit the pinned self-hosted runtime without a third-party CDN. */
|
||||
function ruffleAssets(): Plugin {
|
||||
const files = readdirSync(RUFFLE_DIRECTORY).filter((name) => RUFFLE_ASSET_PATTERN.test(name))
|
||||
let building = false
|
||||
|
||||
return {
|
||||
name: 'plspace-ruffle-assets',
|
||||
configResolved(config) {
|
||||
building = config.command === 'build'
|
||||
},
|
||||
buildStart() {
|
||||
if (!building) return
|
||||
for (const name of files) {
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: `ruffle/${name}`,
|
||||
source: readFileSync(`${RUFFLE_DIRECTORY}/${name}`),
|
||||
})
|
||||
}
|
||||
},
|
||||
configureServer(server) {
|
||||
server.middlewares.use('/ruffle', (request, response, next) => {
|
||||
const name = decodeURIComponent((request.url ?? '').replace(/^\//, '').split('?')[0])
|
||||
if (!files.includes(name)) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
response.setHeader(
|
||||
'Content-Type',
|
||||
name.endsWith('.wasm') ? 'application/wasm' : name.endsWith('.js') ? 'text/javascript' : 'text/plain',
|
||||
)
|
||||
response.end(readFileSync(`${RUFFLE_DIRECTORY}/${name}`))
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fully static output: the app talks to a Mastodon/Pleroma server directly from
|
||||
// the browser, so `dist/` can be dropped on any static host (or file://-ish CDN).
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [svelte(), svelteTesting()],
|
||||
plugins: [svelte(), svelteTesting(), ruffleAssets()],
|
||||
resolve: {
|
||||
alias: {
|
||||
$lib: fileURLToPath(new URL('./src/lib', import.meta.url)),
|
||||
|
||||
Reference in New Issue
Block a user