From 54006ac798441761025b1c1237e1844ff6dfcf6b Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 19 Jan 2021 21:54:14 +0100 Subject: [PATCH] use pluginReplace for env variables --- packages/editor/src/Editor.ts | 2 +- packages/editor/src/common/globals.ts | 5 +---- packages/editor/src/core/bpString.ts | 2 +- packages/website/tools/fuse.ts | 10 +++++++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/editor/src/Editor.ts b/packages/editor/src/Editor.ts index dc11c2b..a9bf054 100644 --- a/packages/editor/src/Editor.ts +++ b/packages/editor/src/Editor.ts @@ -15,7 +15,7 @@ import { initActions, registerAction } from './actions' export class Editor { public async init(canvas: HTMLCanvasElement): Promise { await Promise.all([ - fetch(`${G.STATIC_URL}data.json`) + fetch('__STATIC_URL__/data.json') .then(res => res.text()) .then(modules => loadData(modules)), BasisLoader.loadTranscoder(basisTranscoderJS, basisTranscoderWASM), diff --git a/packages/editor/src/common/globals.ts b/packages/editor/src/common/globals.ts index f040175..8242128 100644 --- a/packages/editor/src/common/globals.ts +++ b/packages/editor/src/common/globals.ts @@ -39,7 +39,7 @@ function getBT(path: string): Promise { } function getTexture(path: string, x = 0, y = 0, w = 0, h = 0): PIXI.Texture { - const key = `${STATIC_URL}${path.replace('.png', '.basis')}` + const key = `__STATIC_URL__/${path.replace('.png', '.basis')}` const KK = `${key}-${x}-${y}-${w}-${h}` let t = textureCache.get(KK) if (t) return t @@ -60,10 +60,7 @@ function getTexture(path: string, x = 0, y = 0, w = 0, h = 0): PIXI.Texture { return t } -const STATIC_URL = 'data/' - export default { - STATIC_URL, debug, hr, BPC, diff --git a/packages/editor/src/core/bpString.ts b/packages/editor/src/core/bpString.ts index 5f08c05..e8a745a 100644 --- a/packages/editor/src/core/bpString.ts +++ b/packages/editor/src/core/bpString.ts @@ -147,7 +147,7 @@ function getBlueprintOrBookFromSource(source: string): Promise reject(e) } }).then((url: URL) => { - const corsProxy = 'https://api.allorigins.win/raw?url=' + const corsProxy = '__CORS_PROXY_URL__' console.log(`Loading data from: ${url}`) const pathParts = url.pathname.slice(1).split('/') diff --git a/packages/website/tools/fuse.ts b/packages/website/tools/fuse.ts index 0ea80ce..0f69c9f 100644 --- a/packages/website/tools/fuse.ts +++ b/packages/website/tools/fuse.ts @@ -1,5 +1,5 @@ import { join } from 'path' -import { fusebox, sparky, pluginLink } from 'fuse-box' +import { fusebox, sparky, pluginLink, pluginReplace } from 'fuse-box' import { IDevServerProps } from 'fuse-box/devServer/devServerProps' import { Context as FuseBoxContext } from 'fuse-box/core/context' import { wrapContents } from 'fuse-box/plugins/pluginStrings' @@ -37,6 +37,14 @@ class Context { plugins: [ this.luaPlugin, pluginLink(/basis_transcoder\.(js|wasm)$/, { useDefault: true }), + pluginReplace({ + __CORS_PROXY_URL__: runServer + ? 'https://api.allorigins.win/raw?url=' + : '/corsproxy?url=', + __STATIC_URL__: runServer + ? '/data' + : 'https://static-fbe.teoxoy.com/file/factorio-blueprint-editor', + }), ], cache: { enabled: runServer, strategy: 'memory' }, hmr: { plugin: p('./hmr.ts') },