Skip to content

Commit 753b6c5

Browse files
committed
refactor(stackblitz): move html playgrounds to node and vite
1 parent 36ffb61 commit 753b6c5

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

src/components/global/Playground/stackblitz.utils.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,25 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => {
5454
options?.includeIonContent ? 'html/index.withContent.html' : 'html/index.html',
5555
'html/variables.css',
5656
'html/package.json',
57+
'html/tsconfig.json',
58+
'html/vite.config.ts',
5759
],
5860
options.version
5961
);
6062

63+
const package_json = JSON.parse(defaultFiles[3]);
64+
6165
const indexHtml = 'index.html';
6266
const files = {
63-
'index.ts': defaultFiles[0],
67+
'package.json': JSON.stringify(package_json, null, 2),
68+
'src/index.ts': defaultFiles[0],
6469
[indexHtml]: defaultFiles[1],
65-
'theme/variables.css': defaultFiles[2],
70+
'src/theme/variables.css': defaultFiles[2],
71+
'tsconfig.json': defaultFiles[4],
72+
'vite.config.ts': defaultFiles[5],
6673
...options?.files,
6774
};
6875

69-
const package_json = defaultFiles[3];
70-
7176
files[indexHtml] = defaultFiles[1].replace(/{{ TEMPLATE }}/g, code).replace(
7277
'</head>',
7378
`
@@ -82,23 +87,18 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => {
8287
`
8388
);
8489

85-
let dependencies = {};
86-
try {
87-
dependencies = {
88-
...dependencies,
89-
...JSON.parse(package_json).dependencies,
90-
...options?.dependencies,
90+
if (options?.dependencies) {
91+
package_json.dependencies = {
92+
...package_json.dependencies,
93+
...options.dependencies,
9194
};
92-
} catch (e) {
93-
console.error('Failed to parse package.json contents', e);
9495
}
9596

9697
sdk.openProject({
97-
template: 'typescript',
98+
template: 'node',
9899
title: options?.title ?? DEFAULT_EDITOR_TITLE,
99100
description: options?.description ?? DEFAULT_EDITOR_DESCRIPTION,
100101
files,
101-
dependencies,
102102
});
103103
};
104104

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<html>
22

3-
<head>
4-
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@8/css/core.css" />
5-
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@8/css/ionic.bundle.css" />
6-
</head>
7-
83
<body>
94
<ion-app>
105
{{ TEMPLATE }}
116
</ion-app>
7+
8+
<script type="module" src="./src/index.ts"></script>
129
</body>
1310

1411
</html>
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
<html>
22

3-
<head>
4-
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@8/css/core.css" />
5-
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@8/css/ionic.bundle.css" />
6-
</head>
7-
83
<body>
94
<ion-app>
105
<ion-content class="ion-padding">
116
{{ TEMPLATE }}
127
</ion-content>
138
</ion-app>
9+
10+
<script type="module" src="./src/index.ts"></script>
1411
</body>
1512

1613
</html>
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
{
2+
"name": "html-starter",
3+
"private": true,
4+
"type": "module",
5+
"main": "index.ts",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"start": "vite preview"
10+
},
211
"dependencies": {
312
"@ionic/core": "8.6.0",
4-
"ionicons": "8.0.8"
13+
"ionicons": "8.0.8",
14+
"typescript": "^5.0.0",
15+
"vite": "^4.0.0"
516
}
617
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./",
4+
"target": "esnext",
5+
"module": "nodenext",
6+
"moduleResolution": "nodenext",
7+
"outDir": "dist",
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"lib": ["esnext", "dom"],
13+
"resolveJsonModule": true,
14+
"allowSyntheticDefaultImports": true,
15+
"isolatedModules": true,
16+
"types": ["node"]
17+
},
18+
"include": ["src/**/*.ts"]
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite';
2+
3+
export default defineConfig({
4+
optimizeDeps: {
5+
exclude: ['@ionic/core'],
6+
},
7+
});

0 commit comments

Comments
 (0)