From 24288a554d445f4fc12ad278e0736cd1e494f6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 14 Oct 2022 10:05:25 +0200 Subject: [PATCH] fix(editor): fix `BASE_PATH` for Vite dev mode (#4342) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :bug: Fix `BASE_PATH` for Vite dev mode * don't use the string `/{{BASE_PATH}}/` as it gets replaces in build * fix the static urls on windows * ffs node 14 Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ --- packages/cli/src/Server.ts | 2 +- packages/editor-ui/src/router.ts | 3 +-- packages/editor-ui/src/shims.d.ts | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index eb5da9492c..7b561f86ee 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1800,7 +1800,7 @@ class App { const srcFile = await readFile(filePath, 'utf8'); let payload = srcFile .replace(basePathRegEx, n8nPath) - .replace(/\/static\//g, pathJoin(n8nPath, 'static/')); + .replace(/\/static\//g, n8nPath + 'static/'); if (filePath.endsWith('index.html')) { payload = payload.replace(closingTitleTag, closingTitleTag + scriptsString); } diff --git a/packages/editor-ui/src/router.ts b/packages/editor-ui/src/router.ts index 24359f0d45..ca2944998a 100644 --- a/packages/editor-ui/src/router.ts +++ b/packages/editor-ui/src/router.ts @@ -55,8 +55,7 @@ function getTemplatesRedirect(store: Store) { const router = new Router({ mode: 'history', - // @ts-ignore - base: window.BASE_PATH ?? '/', + base: import.meta.env.DEV ? '/' : window.BASE_PATH ?? '/', scrollBehavior(to, from, savedPosition) { // saved position == null means the page is NOT visited from history (back button) if (savedPosition === null && to.name === VIEWS.TEMPLATES && to.meta) { diff --git a/packages/editor-ui/src/shims.d.ts b/packages/editor-ui/src/shims.d.ts index 467ca274f1..eb1c83fcdd 100644 --- a/packages/editor-ui/src/shims.d.ts +++ b/packages/editor-ui/src/shims.d.ts @@ -5,6 +5,10 @@ declare module 'markdown-it-emoji'; declare module 'markdown-it-task-lists'; declare global { + interface Window { + BASE_PATH: string; + } + namespace JSX { // tslint:disable no-empty-interface interface Element extends VNode {}