Skip to content

Commit f49ee37

Browse files
committed
chore: Formatting
1 parent e294607 commit f49ee37

File tree

6 files changed

+66
-61
lines changed

6 files changed

+66
-61
lines changed

src/index.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
1919
const packageManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm';
2020

2121
prompts.intro(
22-
kl.trueColor(...brandColor)('Preact - Fast 3kB alternative to React with the same modern API')
22+
kl.trueColor(...brandColor)(
23+
'Preact - Fast 3kB alternative to React with the same modern API',
24+
),
2325
);
2426

2527
const { dir, language, useRouter, useESLint, appType } = await prompts.group(
@@ -36,14 +38,15 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
3638
}
3739
},
3840
}),
39-
appType : () => prompts.select({
40-
message: 'Project Type:',
41-
initialValue: 'spa',
42-
options: [
43-
{ value: 'spa', label: 'Single Page Application (only client-side)' },
44-
{ value: 'ssg', label: 'Static Site Generation (prerenders pages)' },
45-
],
46-
}),
41+
appType: () =>
42+
prompts.select({
43+
message: 'Project Type:',
44+
initialValue: 'spa',
45+
options: [
46+
{ value: 'spa', label: 'Single Page Application (only client-side)' },
47+
{ value: 'ssg', label: 'Static Site Generation (prerenders pages)' },
48+
],
49+
}),
4750
language: () =>
4851
prompts.select({
4952
message: 'Project language:',
@@ -53,11 +56,13 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
5356
{ value: 'ts', label: 'TypeScript' },
5457
],
5558
}),
56-
useRouter: ({ results }) => results.appType === 'spa' ?
57-
prompts.confirm({
58-
message: 'Use router?',
59-
initialValue: false,
60-
}) : Promise.resolve(false),
59+
useRouter: ({ results }) =>
60+
results.appType === 'spa'
61+
? prompts.confirm({
62+
message: 'Use router?',
63+
initialValue: false,
64+
})
65+
: Promise.resolve(false),
6166
useESLint: () =>
6267
prompts.confirm({
6368
message: 'Use ESLint?',
@@ -77,13 +82,13 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
7782
await useSpinner(
7883
'Setting up your project directory...',
7984
() => scaffold(targetDir, { useTS, useRouter, useESLint, appType }),
80-
'Set up project directory'
85+
'Set up project directory',
8186
);
8287

8388
await useSpinner(
8489
'Installing project dependencies...',
8590
() => installDeps(targetDir, packageManager, { useTS, useRouter, useESLint, appType }),
86-
'Installed project dependencies'
91+
'Installed project dependencies',
8792
);
8893

8994
if (!skipHint) {

templates/ssr/renderer/PageShell.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { PageContextProvider } from './usePageContext'
1+
import { PageContextProvider } from './usePageContext';
22
import './PageShell.css';
33

4-
export { PageShell }
4+
export { PageShell };
55

66
function PageShell({ pageContext, children }) {
7-
return (
8-
<PageContextProvider pageContext={pageContext}>
9-
<Header url={pageContext.urlPathname} />
10-
<main>{children}</main>
11-
</PageContextProvider>
12-
)
7+
return (
8+
<PageContextProvider pageContext={pageContext}>
9+
<Header url={pageContext.urlPathname} />
10+
<main>{children}</main>
11+
</PageContextProvider>
12+
);
1313
}
1414

15-
1615
export function Header({ url }) {
1716
return (
1817
<header>

templates/ssr/renderer/_default.page.client.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
export { render }
1+
export { render };
22

3-
import { hydrate } from 'preact'
4-
import { PageShell } from './PageShell'
3+
import { hydrate } from 'preact';
4+
import { PageShell } from './PageShell';
55

66
// This render() hook only supports SSR, see https://vite-plugin-ssr.com/render-modes for how to modify render() to support SPA
77
async function render(pageContext) {
8-
const { Page, pageProps } = pageContext
9-
if (!Page) throw new Error('Client-side render() hook expects pageContext.Page to be defined')
10-
const root = document.getElementById('app')
11-
if (!root) throw new Error('DOM element #app not found')
8+
const { Page, pageProps } = pageContext;
9+
if (!Page) throw new Error('Client-side render() hook expects pageContext.Page to be defined');
10+
const root = document.getElementById('app');
11+
if (!root) throw new Error('DOM element #app not found');
1212

1313
hydrate(
1414
<PageShell pageContext={pageContext}>
15-
<Page {...pageProps} />
15+
<Page {...pageProps} />
1616
</PageShell>,
17-
root
18-
)
17+
root,
18+
);
1919
}
2020

2121
/* To enable Client-side Routing:
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
export { render }
1+
export { render };
22
// See https://vite-plugin-ssr.com/data-fetching
3-
export const passToClient = ['pageProps', 'urlPathname']
3+
export const passToClient = ['pageProps', 'urlPathname'];
44

5-
import { renderToString } from 'preact-render-to-string'
6-
import { PageShell } from './PageShell'
7-
import { escapeInject, dangerouslySkipEscape } from 'vite-plugin-ssr/server'
5+
import { renderToString } from 'preact-render-to-string';
6+
import { PageShell } from './PageShell';
7+
import { escapeInject, dangerouslySkipEscape } from 'vite-plugin-ssr/server';
88

99
async function render(pageContext) {
10-
const { Page, pageProps } = pageContext
10+
const { Page, pageProps } = pageContext;
1111
// This render() hook only supports SSR, see https://vite-plugin-ssr.com/render-modes for how to modify render() to support SPA
12-
if (!Page) throw new Error('My render() hook expects pageContext.Page to be defined')
12+
if (!Page) throw new Error('My render() hook expects pageContext.Page to be defined');
1313
const pageHtml = renderToString(
1414
<PageShell pageContext={pageContext}>
1515
<Page {...pageProps} />
16-
</PageShell>
17-
)
16+
</PageShell>,
17+
);
1818

1919
// See https://vite-plugin-ssr.com/head
20-
const { documentProps } = pageContext.exports
21-
const title = (documentProps && documentProps.title) || 'Vite SSR app'
22-
const desc = (documentProps && documentProps.description) || 'App using Vite + vite-plugin-ssr'
20+
const { documentProps } = pageContext.exports;
21+
const title = (documentProps && documentProps.title) || 'Vite SSR + Preact';
22+
const desc =
23+
(documentProps && documentProps.description) || 'Preact app with Vite and vite-plugin-ssr';
2324

2425
const documentHtml = escapeInject`<!DOCTYPE html>
2526
<html lang="en">
2627
<head>
2728
<meta charset="UTF-8" />
28-
<link rel="icon" href="/vite.svg" />
29+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
2930
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
3031
<meta name="color-scheme" content="light dark" />
3132
<meta name="description" content="${desc}" />
@@ -34,12 +35,12 @@ async function render(pageContext) {
3435
<body>
3536
<div id="app">${dangerouslySkipEscape(pageHtml)}</div>
3637
</body>
37-
</html>`
38+
</html>`;
3839

39-
return {
40+
return {
4041
documentHtml,
4142
pageContext: {
4243
// We can add some `pageContext` here, which is useful if we want to do page redirection https://vite-plugin-ssr.com/page-redirection
43-
}
44-
}
44+
},
45+
};
4546
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// `usePageContext` allows us to access `pageContext` in any Preact component.
22
// See https://vite-plugin-ssr.com/pageContext-anywhere
33

4-
import { createContext } from 'preact'
5-
import { useContext } from 'preact/hooks'
4+
import { createContext } from 'preact';
5+
import { useContext } from 'preact/hooks';
66

7-
export { PageContextProvider }
8-
export { usePageContext }
7+
export { PageContextProvider };
8+
export { usePageContext };
99

10-
const Context = createContext(undefined)
10+
const Context = createContext(undefined);
1111

1212
function PageContextProvider({ pageContext, children }) {
13-
return <Context.Provider value={pageContext}>{children}</Context.Provider>
13+
return <Context.Provider value={pageContext}>{children}</Context.Provider>;
1414
}
1515

1616
function usePageContext() {
17-
const pageContext = useContext(Context)
18-
return pageContext
17+
const pageContext = useContext(Context);
18+
return pageContext;
1919
}

templates/ssr/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from 'vite';
22
import preact from '@preact/preset-vite';
3-
import ssr from 'vite-plugin-ssr/plugin'
3+
import ssr from 'vite-plugin-ssr/plugin';
44

55
// https://vitejs.dev/config/
66
export default defineConfig({

0 commit comments

Comments
 (0)