Skip to content

Commit 9bc402c

Browse files
committed
use SvelteKit instead
1 parent 12f7095 commit 9bc402c

File tree

4 files changed

+29
-56
lines changed

4 files changed

+29
-56
lines changed

apps/svelte.dev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"prettier-plugin-svelte": "^3.3.2",
7474
"satori": "^0.10.13",
7575
"satori-html": "^0.3.2",
76+
"sv": "^0.6.8",
7677
"svelte": "5.14.0",
7778
"svelte-check": "^4.1.1",
7879
"svelte-preprocess": "^6.0.3",

apps/svelte.dev/scripts/get_svelte_template.js

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
// @ts-check
2-
import { execSync } from 'node:child_process';
3-
import {
4-
copyFileSync,
5-
mkdirSync,
6-
readdirSync,
7-
readFileSync,
8-
rmSync,
9-
statSync,
10-
writeFileSync
11-
} from 'node:fs';
2+
import { readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
123
import { join } from 'node:path';
134
import { fileURLToPath } from 'node:url';
5+
import { create } from 'sv';
146

157
// This download the currente Vite template from Github, adjusts it to our needs, and saves it to static/svelte-template.json
168
// This is used by the Svelte REPL as part of the "download project" feature
@@ -25,29 +17,8 @@ try {
2517
process.exit(0);
2618
}
2719
} catch {
28-
// fetch svelte app
29-
rmSync(output_dir, { force: true, recursive: true });
30-
execSync(`npx degit vitejs/vite/packages/create-vite/template-svelte-ts ${output_dir}`, {
31-
stdio: 'inherit'
32-
});
33-
34-
// remove everything that's not needed
35-
rmSync(join(output_dir, 'src/assets'), { force: true, recursive: true });
36-
rmSync(join(output_dir, 'src/lib'), { force: true, recursive: true });
37-
rmSync(join(output_dir, 'src/app.css'), { force: true, recursive: true });
38-
rmSync(join(output_dir, 'src/App.svelte'), { force: true, recursive: true });
39-
rmSync(join(output_dir, 'src/main.ts'), { force: true, recursive: true });
40-
rmSync(join(output_dir, 'public'), { force: true, recursive: true });
41-
42-
// add what we need
43-
mkdirSync(join(output_dir, 'public'));
44-
copyFileSync(
45-
fileURLToPath(new URL('../static/favicon.png')),
46-
join(output_dir, 'public/favicon.png')
47-
);
48-
49-
// build svelte-app.json
50-
const files = [];
20+
// create Svelte-Kit skelton app
21+
create(output_dir, { template: 'minimal', types: 'typescript', name: 'your-app' });
5122

5223
function get_all_files(dir) {
5324
const files = [];
@@ -58,34 +29,37 @@ try {
5829
if (item.isDirectory()) {
5930
files.push(...get_all_files(full_path));
6031
} else {
61-
files.push(full_path);
32+
files.push(full_path.replaceAll('\\', '/'));
6233
}
6334
}
6435

6536
return files;
6637
}
6738

6839
const all_files = get_all_files(output_dir);
40+
const files = [];
6941

7042
for (let path of all_files) {
7143
const bytes = readFileSync(path);
7244
const string = bytes.toString();
7345
let data = bytes.compare(Buffer.from(string)) === 0 ? string : [...bytes];
7446

75-
// handle some special cases
76-
path = path.slice(output_dir.length + 1);
77-
if (path.endsWith('_gitignore')) path = path.slice(0, -10) + '.gitignore';
78-
79-
if (path.endsWith('index.html')) {
80-
data = /** @type {any} */ (data).replace(
81-
'<link rel="icon" type="image/svg+xml" href="/vite.svg" />',
82-
'<link rel="icon" type="image/png" href="/favicon.png" />'
83-
);
47+
if (path.endsWith('routes/+page.svelte')) {
48+
data = `<script>\nimport App from './App.svelte';\n</script>\n\n<App />\n`;
8449
}
8550

86-
files.push({ path, data });
51+
files.push({ path: path.slice(output_dir.length + 1), data });
8752
}
8853

54+
files.push({
55+
path: 'src/routes/+page.js',
56+
data:
57+
"// Because we don't know whether or not your playground app can run in a server environment, we disable server-side rendering.\n" +
58+
'// Make sure to test whether or not you can re-enable it, as SSR improves perceived performance and site accessibility.\n' +
59+
'// Read more about this option here: https://svelte.dev/docs/kit/page-options#ssr\n' +
60+
'export const ssr = false;\n'
61+
});
62+
8963
writeFileSync(output_file, JSON.stringify(files));
9064

9165
// remove output dir afterwards to prevent it messing with Vite watcher

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,10 @@
136136
137137
files.push(
138138
...components.map((component) => ({
139-
path: `src/${component.name}`,
139+
path: `src/routes/${component.name}`,
140140
data: (component as File).contents
141141
}))
142142
);
143-
files.push({
144-
path: `src/main.ts`,
145-
data: `import App from './App.svelte';
146-
import { mount } from 'svelte';
147-
148-
const app = mount(App, {
149-
target: document.body
150-
});
151-
152-
export default app;`
153-
});
154143
155144
const downloadBlob = (blob: any, filename: string) => {
156145
const url = URL.createObjectURL(blob);

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)