From f58f0eaf927a9f41ea31facdf9107ca52241a626 Mon Sep 17 00:00:00 2001 From: ShittyKopper Date: Mon, 15 Jan 2024 18:11:03 +0300 Subject: [PATCH] upd: make the mod tracker work in dev mode this is an ugly hack but it's a ugly hack that works. --- packages/frontend/@types/global.d.ts | 1 + packages/frontend/src/scripts/chiptune2.ts | 9 ++++++++- packages/frontend/vite.config.local-dev.ts | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/frontend/@types/global.d.ts b/packages/frontend/@types/global.d.ts index 7d9335cc52..a707b38f1a 100644 --- a/packages/frontend/@types/global.d.ts +++ b/packages/frontend/@types/global.d.ts @@ -16,3 +16,4 @@ declare const _DATA_TRANSFER_DECK_COLUMN_: string; // for dev-mode declare const _LANGS_FULL_: string[][]; +declare const __DIRNAME__: string; diff --git a/packages/frontend/src/scripts/chiptune2.ts b/packages/frontend/src/scripts/chiptune2.ts index 7fef2103dd..717c43e1dc 100644 --- a/packages/frontend/src/scripts/chiptune2.ts +++ b/packages/frontend/src/scripts/chiptune2.ts @@ -233,7 +233,14 @@ export class ChiptuneJsPlayer { async createLibopenmptNode(buffer: ArrayBuffer) { if (!this.libopenmpt) { const libopenmpt = await import('libopenmpt-wasm'); - this.libopenmpt = await libopenmpt.default(); + this.libopenmpt = await libopenmpt.default( _DEV_ ? { + // hack to make libopenmpt load in dev mode + locateFile(file) { + const url = new URL(window.location.href); + url.pathname = `/@fs/${__DIRNAME__}/node_modules/libopenmpt-wasm/${file}`; + return url.href; + }, + } : {}); } return new ChiptuneProcessorNode(this, buffer); diff --git a/packages/frontend/vite.config.local-dev.ts b/packages/frontend/vite.config.local-dev.ts index 41b4561e28..703df015ba 100644 --- a/packages/frontend/vite.config.local-dev.ts +++ b/packages/frontend/vite.config.local-dev.ts @@ -55,6 +55,7 @@ const devConfig = { define: { ...defaultConfig.define, _LANGS_FULL_: JSON.stringify(Object.entries(locales)), + __DIRNAME__: JSON.stringify(__dirname), }, };