Skip to content

Commit aea491d

Browse files
committed
format
1 parent a6e6d96 commit aea491d

File tree

9 files changed

+125
-126
lines changed

9 files changed

+125
-126
lines changed

packages/playground/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dist
22
dist-ssr
3-
*.local
3+
*.local

packages/playground/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ If you have state that's important to retain within a component, consider creati
4242
```js
4343
// store.js
4444
// An extremely simple external store
45-
import { writable } from 'svelte/store'
46-
export default writable(0)
45+
import { writable } from 'svelte/store';
46+
export default writable(0);
4747
```

packages/playground/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<!--app-head-->
7-
</head>
8-
<body>
9-
<div id="app"><!--app-html--></div>
10-
<script type="module" src="/src/entry-client.js"></script>
11-
</body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<!--app-head-->
7+
</head>
8+
<body>
9+
<div id="app"><!--app-html--></div>
10+
<script type="module" src="/src/entry-client.js"></script>
11+
</body>
1212
</html>

packages/playground/jsconfig.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
{
2-
"compilerOptions": {
3-
"moduleResolution": "Node",
4-
"target": "ESNext",
5-
"module": "ESNext",
6-
/**
7-
* svelte-preprocess cannot figure out whether you have
8-
* a value or a type, so tell TypeScript to enforce using
9-
* `import type` instead of `import` for Types.
10-
*/
11-
"importsNotUsedAsValues": "error",
12-
"isolatedModules": true,
13-
"resolveJsonModule": true,
14-
/**
15-
* To have warnings / errors of the Svelte compiler at the
16-
* correct position, enable source maps by default.
17-
*/
18-
"sourceMap": true,
19-
"esModuleInterop": true,
20-
"skipLibCheck": true,
21-
"forceConsistentCasingInFileNames": true,
22-
/**
23-
* Typecheck JS in `.svelte` and `.js` files by default.
24-
* Disable this if you'd like to use dynamic types.
25-
*/
26-
"checkJs": true
27-
},
28-
/**
29-
* Use global.d.ts instead of compilerOptions.types
30-
* to avoid limiting type declarations.
31-
*/
32-
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
2+
"compilerOptions": {
3+
"moduleResolution": "Node",
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
/**
7+
* svelte-preprocess cannot figure out whether you have
8+
* a value or a type, so tell TypeScript to enforce using
9+
* `import type` instead of `import` for Types.
10+
*/
11+
"importsNotUsedAsValues": "error",
12+
"isolatedModules": true,
13+
"resolveJsonModule": true,
14+
/**
15+
* To have warnings / errors of the Svelte compiler at the
16+
* correct position, enable source maps by default.
17+
*/
18+
"sourceMap": true,
19+
"esModuleInterop": true,
20+
"skipLibCheck": true,
21+
"forceConsistentCasingInFileNames": true,
22+
/**
23+
* Typecheck JS in `.svelte` and `.js` files by default.
24+
* Disable this if you'd like to use dynamic types.
25+
*/
26+
"checkJs": true
27+
},
28+
/**
29+
* Use global.d.ts instead of compilerOptions.types
30+
* to avoid limiting type declarations.
31+
*/
32+
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
3333
}

packages/playground/package.json

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
{
2-
"name": "playground",
3-
"private": true,
4-
"version": "0.0.0",
5-
"type": "module",
6-
"scripts": {
7-
"dev": "node server",
8-
"build": "npm run build:client && npm run build:server",
9-
"build:client": "vite build --ssrManifest --outDir dist/client",
10-
"build:server": "vite build --ssr src/entry-server.js --outDir dist/server",
11-
"preview": "cross-env NODE_ENV=production node server"
12-
},
13-
"dependencies": {
14-
"compression": "^1.7.4",
15-
"express": "^4.18.2",
16-
"sirv": "^2.0.3"
17-
},
18-
"devDependencies": {
19-
"@sveltejs/vite-plugin-svelte": "^2.4.1",
20-
"cross-env": "^7.0.3",
21-
"svelte": "workspace:*",
22-
"vite": "^4.3.9"
23-
}
24-
}
2+
"name": "playground",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "node server",
8+
"format": "prettier . --cache --plugin-search-dir=. --write",
9+
"build": "npm run build:client && npm run build:server",
10+
"build:client": "vite build --ssrManifest --outDir dist/client",
11+
"build:server": "vite build --ssr src/entry-server.js --outDir dist/server",
12+
"preview": "cross-env NODE_ENV=production node server"
13+
},
14+
"dependencies": {
15+
"compression": "^1.7.4",
16+
"express": "^4.18.2",
17+
"sirv": "^2.0.3"
18+
},
19+
"devDependencies": {
20+
"@sveltejs/vite-plugin-svelte": "^2.4.1",
21+
"cross-env": "^7.0.3",
22+
"svelte": "workspace:*",
23+
"vite": "^4.3.9"
24+
}
25+
}

packages/playground/server.js

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,69 @@
1-
import fs from 'node:fs/promises'
2-
import express from 'express'
1+
import fs from 'node:fs/promises';
2+
import express from 'express';
33

44
// Constants
5-
const isProduction = process.env.NODE_ENV === 'production'
6-
const port = process.env.PORT || 5173
7-
const base = process.env.BASE || '/'
5+
const isProduction = process.env.NODE_ENV === 'production';
6+
const port = process.env.PORT || 5173;
7+
const base = process.env.BASE || '/';
88

99
// Cached production assets
10-
const templateHtml = isProduction
11-
? await fs.readFile('./dist/client/index.html', 'utf-8')
12-
: ''
10+
const templateHtml = isProduction ? await fs.readFile('./dist/client/index.html', 'utf-8') : '';
1311
const ssrManifest = isProduction
14-
? await fs.readFile('./dist/client/ssr-manifest.json', 'utf-8')
15-
: undefined
12+
? await fs.readFile('./dist/client/ssr-manifest.json', 'utf-8')
13+
: undefined;
1614

1715
// Create http server
18-
const app = express()
16+
const app = express();
1917

2018
// Add Vite or respective production middlewares
21-
let vite
19+
let vite;
2220
if (!isProduction) {
23-
const { createServer } = await import('vite')
24-
vite = await createServer({
25-
server: { middlewareMode: true },
26-
appType: 'custom',
27-
base
28-
})
29-
app.use(vite.middlewares)
21+
const { createServer } = await import('vite');
22+
vite = await createServer({
23+
server: { middlewareMode: true },
24+
appType: 'custom',
25+
base
26+
});
27+
app.use(vite.middlewares);
3028
} else {
31-
const compression = (await import('compression')).default
32-
const sirv = (await import('sirv')).default
33-
app.use(compression())
34-
app.use(base, sirv('./dist/client', { extensions: [] }))
29+
const compression = (await import('compression')).default;
30+
const sirv = (await import('sirv')).default;
31+
app.use(compression());
32+
app.use(base, sirv('./dist/client', { extensions: [] }));
3533
}
3634

3735
// Serve HTML
3836
app.use('*', async (req, res) => {
39-
try {
40-
const url = req.originalUrl.replace(base, '')
37+
try {
38+
const url = req.originalUrl.replace(base, '');
4139

42-
let template
43-
let render
44-
if (!isProduction) {
45-
// Always read fresh template in development
46-
template = await fs.readFile('./index.html', 'utf-8')
47-
template = await vite.transformIndexHtml(url, template)
48-
render = (await vite.ssrLoadModule('/src/entry-server.js')).render
49-
} else {
50-
template = templateHtml
51-
render = (await import('./dist/server/entry-server.js')).render
52-
}
40+
let template;
41+
let render;
42+
if (!isProduction) {
43+
// Always read fresh template in development
44+
template = await fs.readFile('./index.html', 'utf-8');
45+
template = await vite.transformIndexHtml(url, template);
46+
render = (await vite.ssrLoadModule('/src/entry-server.js')).render;
47+
} else {
48+
template = templateHtml;
49+
render = (await import('./dist/server/entry-server.js')).render;
50+
}
5351

54-
const rendered = await render(url, ssrManifest)
52+
const rendered = await render(url, ssrManifest);
5553

56-
const html = template
57-
.replace(`<!--app-head-->`, rendered.head ?? '')
58-
.replace(`<!--app-html-->`, rendered.html ?? '')
54+
const html = template
55+
.replace(`<!--app-head-->`, rendered.head ?? '')
56+
.replace(`<!--app-html-->`, rendered.html ?? '');
5957

60-
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
61-
} catch (e) {
62-
vite?.ssrFixStacktrace(e)
63-
console.log(e.stack)
64-
res.status(500).end(e.stack)
65-
}
66-
})
58+
res.status(200).set({ 'Content-Type': 'text/html' }).end(html);
59+
} catch (e) {
60+
vite?.ssrFixStacktrace(e);
61+
console.log(e.stack);
62+
res.status(500).end(e.stack);
63+
}
64+
});
6765

6866
// Start http server
6967
app.listen(port, () => {
70-
console.log(`Server started at http://localhost:${port}`)
71-
})
68+
console.log(`Server started at http://localhost:${port}`);
69+
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import './app.css'
2-
import App from './App.svelte'
1+
import './app.css';
2+
import App from './App.svelte';
33

44
new App({
5-
target: document.getElementById('app'),
6-
hydrate: true
7-
})
5+
target: document.getElementById('app'),
6+
hydrate: true
7+
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import App from './App.svelte'
1+
import App from './App.svelte';
22

33
export function render() {
4-
// @ts-ignore
5-
return App.render()
4+
// @ts-ignore
5+
return App.render();
66
}

packages/playground/svelte.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
1+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
22

33
export default {
4-
preprocess: vitePreprocess()
5-
}
4+
preprocess: vitePreprocess()
5+
};

0 commit comments

Comments
 (0)