Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed May 24, 2021
1 parent ba150e2 commit 232af03
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion examples/vue-router/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/node_modules/
dist
4 changes: 2 additions & 2 deletions packages/vue-router/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function matchRoutes(
): Promise<null | undefined | RouteMatch> {

const router = createRouter({
routes: routes.map(route => ({ name: route.id, path: route.pageRoute as string, component: {} })),
routes: routes.map(route => ({ name: route.pageId, path: route.pageRoute as string, component: {} })),
history: createWebHistory()
});

Expand All @@ -31,4 +31,4 @@ function sortRoutes() {

function useVueRouter() {
setCustomRouter({ matchRoutes, sortRoutes })
}
}
8 changes: 4 additions & 4 deletions packages/vue-router/src/client/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { reactive, App } from 'vue';
import { Router } from 'vue-router';
import { getRoutes } from '../isomorphic/get-routes';

type ContextProps = Record<string, unknown> & { routes?: {id: string, pageRoute: string}[] }
type ContextProps = Record<string, unknown> & { routes?: {pageId: string, pageRoute: string}[] }

export function vitePluginSsrRoutes(config={}) {
return {
Expand All @@ -18,13 +18,13 @@ export function vitePluginSsrRoutes(config={}) {

routes.forEach(route => {
router.addRoute({
name: route.id,
name: route.pageId,
path: route.pageRoute as string,
meta: {
isViteSsrPageRoute: true
},
props: (route) => contextPropsByPath[route.fullPath],
component: async () => getPageById(route.id)
component: async () => getPageById(route.pageId)
})
})
}
Expand All @@ -47,4 +47,4 @@ export function vitePluginSsrRoutes(config={}) {
});
},
}
}
}
4 changes: 2 additions & 2 deletions packages/vue-router/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function matchRoutes(
): Promise<null | undefined | RouteMatch> {

const router = createRouter({
routes: routes.map(route => ({ name: route.id, path: route.pageRoute as string, component: {} })),
routes: routes.map(route => ({ name: route.pageId, path: route.pageRoute as string, component: {} })),
history: createMemoryHistory()
});

Expand All @@ -31,4 +31,4 @@ function sortRoutes() {

function useVueRouter() {
setCustomRouter({ matchRoutes, sortRoutes })
}
}
4 changes: 2 additions & 2 deletions packages/vue-router/src/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { App, Component } from 'vue';
import { Router } from 'vue-router';
import { getRoutes } from '../isomorphic/get-routes';

type ContextProps = Record<string, unknown> & { urlPathname: string, routes?: {id: string, pageRoute: string}[] }
type ContextProps = Record<string, unknown> & { urlPathname: string, routes?: {pageId: string, pageRoute: string}[] }

type Config = {
contextProps: ContextProps,
Expand Down Expand Up @@ -35,7 +35,7 @@ export function vitePluginSsrRoutes(config: Config) {

routes.forEach(route => {
router.addRoute({
name: route.id,
name: route.pageId,
path: route.pageRoute as string,
meta: {
isViteSsrPageRoute: true
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ function dev(): Plugin {
name: 'vite-plugin-ssr:dev',
apply: 'serve',
config: () => ({
/*
resolve: {
extensions: [ '.js', '.json', '.node', '.ts' ],
},
//*/
ssr: { external: ['vite-plugin-ssr', '@vite-plugin-ssr/vue-router'] },
optimizeDeps: {
entries: ['**/*.page.*([a-zA-Z0-9])', '**/*.page.client.*([a-zA-Z0-9])']
Expand Down
12 changes: 6 additions & 6 deletions src/route.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function resolveRouteFunction(
type PageRoute<T=string | Function | RouteFunctionMatch> = {
pageRouteFile?: string
pageRoute: T
id: PageId
pageId: PageId
}
async function loadPageRoutes(): Promise<Record<PageId, PageRoute>> {
const userRouteFiles = await getPageFiles('.page.route')
Expand All @@ -261,10 +261,10 @@ async function loadPageRoutes(): Promise<Record<PageId, PageRoute>> {
`The default export of ${filePath} should be a string or a function.`
)
const pageRoute = fileExports.default
const id = computePageId(filePath)
const pageId = computePageId(filePath)
const pageRouteFile = filePath

pageRoutes[id] = { pageRoute, pageRouteFile, id }
pageRoutes[pageId] = { pageRoute, pageRouteFile, pageId }
})
)

Expand Down Expand Up @@ -302,8 +302,8 @@ function getRouteStrings(routes: PageRoute[], pageIds: PageId[]) {
const { sortRoutes } = getCustomRouter();

const fsRouteStrings : PageRoute[] = pageIds
.filter(pageId => !routes.some(route => route.id === pageId) && !isErrorPage(pageId))
.map(id => ({ pageRoute: getFilesystemRoute(id, pageIds), id }));
.filter(pageId => !routes.some(route => route.pageId === pageId) && !isErrorPage(pageId))
.map(pageId => ({ pageRoute: getFilesystemRoute(pageId, pageIds), pageId }));

const routeStrings = Object.values(routes)
.filter(route => !isCallable(route.pageRoute));
Expand Down Expand Up @@ -338,7 +338,7 @@ async function matchPathToRegexpRoutes(

for (var ii = 0; ii < routes.length; ++ii) {
const route = routes[ii];
const { pageRoute, id: pageId } = route;
const { pageRoute, pageId } = route;

// Route with `.page.route.js` defined route string
if (typeof pageRoute === 'string') {
Expand Down
5 changes: 1 addition & 4 deletions src/ssrEnv.node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ViteDevServer } from 'vite'
import { RoutingHandler } from './route.shared';

export { setSsrEnv }
export { getSsrEnv }
Expand All @@ -10,15 +9,13 @@ type SsrEnv =
isProduction: false
viteDevServer: ViteDevServer
root: string
baseUrl: string,
customRouting?: RoutingHandler
baseUrl: string
}
| {
isProduction: true
viteDevServer: undefined
root?: string
baseUrl: string
customRouting?: RoutingHandler
}

function getSsrEnv(): SsrEnv {
Expand Down

0 comments on commit 232af03

Please sign in to comment.