Load ruffle

This commit is contained in:
tusooa 2025-02-26 20:23:10 -05:00
commit b46de85926
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51
4 changed files with 50 additions and 2 deletions

40
build/copy_plugin.js Normal file
View file

@ -0,0 +1,40 @@
import serveStatic from 'serve-static'
import { resolve } from 'node:path'
import { cp } from 'node:fs/promises'
const getPrefix = s => {
const padEnd = s.endsWith('/') ? s : s + '/'
return padEnd.startsWith('/') ? padEnd : '/' + padEnd
}
const copyPlugin = ({ inUrl, inFs }) => {
const prefix = getPrefix(inUrl)
const subdir = prefix.slice(1)
let copyTarget
const handler = serveStatic(inFs)
return [{
name: 'copy-plugin-serve',
apply: 'serve',
configureServer (server) {
server.middlewares.use(prefix, handler)
}
}, {
name: 'copy-plugin-build',
apply: 'build',
configResolved (config) {
copyTarget = resolve(config.root, config.build.outDir, subdir)
},
closeBundle: {
order: 'post',
sequential: true,
async handler () {
console.log(`Copying '${inFs}' to ${copyTarget}...`)
await cp(inFs, copyTarget, { recursive: true })
console.log('Done.')
}
}
}]
}
export default copyPlugin

View file

@ -115,6 +115,7 @@
"sass-loader": "13.3.3",
"selenium-server": "3.141.59",
"semver": "7.7.1",
"serve-static": "1.16.2",
"serviceworker-webpack5-plugin": "2.0.0",
"shelljs": "0.8.5",
"sinon": "15.2.0",

View file

@ -1,11 +1,12 @@
const createRuffleService = () => {
let ruffleInstance = null
const getRuffle = () => new Promise((resolve, reject) => {
const getRuffle = async () => new Promise((resolve, reject) => {
if (ruffleInstance) {
resolve(ruffleInstance)
return
}
// Ruffle needs these to be set before it's loaded
// https://github.com/ruffle-rs/ruffle/issues/3952
window.RufflePlayer = {}

View file

@ -1,10 +1,12 @@
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
import { readFile } from 'node:fs/promises'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { VitePWA } from 'vite-plugin-pwa'
import { devSwPlugin, buildSwPlugin, swMessagesPlugin } from './build/sw_plugin.js'
import copyPlugin from './build/copy_plugin.js'
const getLocalDevSettings = async () => {
try {
@ -76,7 +78,11 @@ export default defineConfig(async ({ command }) => {
vueJsx(),
devSwPlugin({ swSrc, swDest }),
buildSwPlugin({ swSrc, swDest }),
swMessagesPlugin()
swMessagesPlugin(),
copyPlugin({
inUrl: '/static/ruffle',
inFs: resolve(projectRoot, 'node_modules/@ruffle-rs/ruffle')
})
],
resolve: {
alias: {