Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(stackblitz): move html playgrounds to node and vite #4062

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/components/global/Playground/stackblitz.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'</head>',
`
Expand All @@ -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,
});
};

Expand Down
7 changes: 2 additions & 5 deletions static/code/stackblitz/v8/html/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<html>

<head>
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@8/css/core.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@8/css/ionic.bundle.css" />
</head>

<body>
<ion-app>
{{ TEMPLATE }}
</ion-app>

<script type="module" src="./src/index.ts"></script>
</body>

</html>
7 changes: 2 additions & 5 deletions static/code/stackblitz/v8/html/index.withContent.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<html>

<head>
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@next/css/core.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@next/css/ionic.bundle.css" />
</head>

<body>
<ion-app>
<ion-content class="ion-padding">
{{ TEMPLATE }}
</ion-content>
</ion-app>

<script type="module" src="./src/index.ts"></script>
</body>

</html>
13 changes: 12 additions & 1 deletion static/code/stackblitz/v8/html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"name": "html-starter",
"private": true,
"type": "module",
"main": "index.ts",
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "vite preview"
},
"dependencies": {
"@ionic/core": "8.5.3",
"ionicons": "7.4.0"
"ionicons": "7.4.0",
"typescript": "^5.0.0",
"vite": "^4.0.0"
}
}
19 changes: 19 additions & 0 deletions static/code/stackblitz/v8/html/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"baseUrl": "./",
"target": "esnext",
"module": "nodenext",
"moduleResolution": "nodenext",
"outDir": "dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext", "dom"],
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"types": ["node"]
},
"include": ["src/**/*.ts"]
}
7 changes: 7 additions & 0 deletions static/code/stackblitz/v8/html/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite';

export default defineConfig({
optimizeDeps: {
exclude: ['@ionic/core'],
},
});