-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
766664b
commit b8bb175
Showing
20 changed files
with
11,002 additions
and
6,407 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Created by bangbang93 on 2017/8/25. | ||
*/ | ||
'use strict' | ||
import {App} from 'vue' | ||
import {createHome} from './entries' | ||
import * as ElementPlusIconsVue from '@element-plus/icons-vue' | ||
|
||
import './utils/prism.ts' | ||
import 'prismjs/themes/prism-okaidia.css' | ||
import 'element-plus/dist/index.css' | ||
|
||
export async function render(): Promise<App> { | ||
const {app, router, store} = createHome() | ||
if (window.__INITIAL_STATE__) { | ||
// We initialize the store state with the data injected from the server | ||
store.replaceState(window.__INITIAL_STATE__) | ||
} | ||
await router.isReady() | ||
router.beforeResolve((to, _, next) => { | ||
const matched = to.matched.flatMap((e) => { | ||
if (e.components) { | ||
return Object.values(e.components) | ||
} | ||
return [] | ||
}) | ||
// 这里如果有加载指示器(loading indicator),就触发 | ||
Promise.all( | ||
matched.map((c) => { | ||
if ('asyncData' in c && c?.asyncData) { | ||
return c.asyncData({store, route: to}) | ||
} | ||
return null | ||
}), | ||
) | ||
.then(() => { | ||
// 停止加载指示器(loading indicator) | ||
next() | ||
}) | ||
.catch(next) | ||
}) | ||
|
||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) { | ||
app.component(key, component) | ||
} | ||
|
||
app.mount('app') | ||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Created by bangbang93 on 2017/8/25. | ||
*/ | ||
'use strict' | ||
import {renderToString} from '@vue/server-renderer' | ||
import * as HttpErrors from 'http-errors' | ||
import {dangerouslySkipEscape, escapeInject} from 'vike' | ||
import {PageContext} from 'vike/types' | ||
import {createHome} from './entries' | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace Vike { | ||
interface PageContext { | ||
origin: string | ||
referer: string | ||
state: Record<string, unknown> | ||
status: object | ||
} | ||
} | ||
} | ||
|
||
export async function render(pageContext: PageContext) { | ||
const {app, router, store} = createHome() | ||
await router.push(pageContext.urlOriginal) | ||
|
||
await router.isReady() | ||
const matchedComponents = router.currentRoute.value.matched.flatMap((e) => { | ||
if (e.components) { | ||
return Object.values(e.components) | ||
} | ||
return [] | ||
}) | ||
if (!matchedComponents.length) { | ||
throw new HttpErrors.NotFound('no such route') | ||
} | ||
await Promise.all( | ||
matchedComponents.map((Component) => { | ||
if (!Component) return Promise.resolve() | ||
if ('asyncData' in Component && Component.asyncData) { | ||
store.commit('setOrigin', pageContext.origin) | ||
store.commit('setReferer', pageContext.referer) | ||
return Component.asyncData({ | ||
store, | ||
route: router.currentRoute.value, | ||
}) | ||
} | ||
return null | ||
}), | ||
) | ||
|
||
pageContext.state = store.state | ||
if (router.currentRoute.value.meta.status) { | ||
pageContext.status = router.currentRoute.value.meta.status | ||
} | ||
|
||
const appHtml = await renderToString(app) | ||
const documentProps = pageContext.exports.documentProps as Record<string, string | undefined> | ||
const title = documentProps?.title || 'Vite SSR app' | ||
const desc = documentProps?.description || 'App using Vite + Vike' | ||
|
||
const documentHtml = escapeInject`<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="description" content="${desc}" /> | ||
<title>${title}</title> | ||
</head> | ||
<body> | ||
<div id="app">${dangerouslySkipEscape(appHtml)}</div> | ||
</body> | ||
</html>` | ||
|
||
return { | ||
documentHtml, | ||
pageContext: { | ||
// We can add some `pageContext` here, | ||
// which is useful if we want to do page redirection | ||
// https://vike.dev/page-redirection | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import vuePlugin from '@vitejs/plugin-vue' | ||
import {fileURLToPath, URL} from 'node:url' | ||
import {fileURLToPath} from 'node:url' | ||
import {defineConfig} from 'vite' | ||
import vike from 'vike/plugin' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
vuePlugin(), | ||
vike(), | ||
], | ||
resolve: { | ||
alias: { | ||
'@': fileURLToPath(new URL('./src', import.meta.url)), | ||
}, | ||
}, | ||
base: '/admin/', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.