From 72916db76c55eff062a44d466eaf1ee9a0db2879 Mon Sep 17 00:00:00 2001 From: Brandy Smith <6577830+brandyscarney@users.noreply.github.com> Date: Mon, 31 Mar 2025 15:34:14 -0400 Subject: [PATCH] refactor(stackblitz): move html playgrounds to node and vite --- .../global/Playground/stackblitz.utils.ts | 28 +++++++++---------- static/code/stackblitz/v8/html/index.html | 7 ++--- .../stackblitz/v8/html/index.withContent.html | 7 ++--- static/code/stackblitz/v8/html/package.json | 13 ++++++++- static/code/stackblitz/v8/html/tsconfig.json | 19 +++++++++++++ static/code/stackblitz/v8/html/vite.config.ts | 7 +++++ 6 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 static/code/stackblitz/v8/html/tsconfig.json create mode 100644 static/code/stackblitz/v8/html/vite.config.ts diff --git a/src/components/global/Playground/stackblitz.utils.ts b/src/components/global/Playground/stackblitz.utils.ts index aed074d6328..f0e1f698d22 100644 --- a/src/components/global/Playground/stackblitz.utils.ts +++ b/src/components/global/Playground/stackblitz.utils.ts @@ -54,20 +54,25 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => { options?.includeIonContent ? 'html/index.withContent.html' : 'html/index.html', 'html/variables.css', 'html/package.json', + 'html/tsconfig.json', + 'html/vite.config.ts', ], options.version ); + const package_json = JSON.parse(defaultFiles[3]); + const indexHtml = 'index.html'; const files = { - 'index.ts': defaultFiles[0], + 'package.json': JSON.stringify(package_json, null, 2), + 'src/index.ts': defaultFiles[0], [indexHtml]: defaultFiles[1], - 'theme/variables.css': defaultFiles[2], + 'src/theme/variables.css': defaultFiles[2], + 'tsconfig.json': defaultFiles[4], + 'vite.config.ts': defaultFiles[5], ...options?.files, }; - const package_json = defaultFiles[3]; - files[indexHtml] = defaultFiles[1].replace(/{{ TEMPLATE }}/g, code).replace( '', ` @@ -82,23 +87,18 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => { ` ); - let dependencies = {}; - try { - dependencies = { - ...dependencies, - ...JSON.parse(package_json).dependencies, - ...options?.dependencies, + if (options?.dependencies) { + package_json.dependencies = { + ...package_json.dependencies, + ...options.dependencies, }; - } catch (e) { - console.error('Failed to parse package.json contents', e); } sdk.openProject({ - template: 'typescript', + template: 'node', title: options?.title ?? DEFAULT_EDITOR_TITLE, description: options?.description ?? DEFAULT_EDITOR_DESCRIPTION, files, - dependencies, }); }; diff --git a/static/code/stackblitz/v8/html/index.html b/static/code/stackblitz/v8/html/index.html index 34f05146a9a..a33492a8bad 100644 --- a/static/code/stackblitz/v8/html/index.html +++ b/static/code/stackblitz/v8/html/index.html @@ -1,14 +1,11 @@ -
- - - -