edge-city

#react#js#ssr

git clone https://git.pyrossh.dev/edge-city

edge-city is a next level meta-framework for react that runs only on edge runtimes


example/vite.config.js
c7f7584 1
import { defineConfig } from 'vite';
c7f7584 2
c7f7584 3
function pagesPlugin(userOptions) {
c7f7584 4
  return {
c7f7584 5
    name: 'vite-plugin-pages',
c7f7584 6
    enforce: 'pre',
c7f7584 7
    async configResolved(config) {
c7f7584 8
      userOptions.resolver = 'react'
c7f7584 9
      ctx = new PageContext(userOptions, config.root)
c7f7584 10
      ctx.setLogger(config.logger)
c7f7584 11
      await ctx.searchGlob()
c7f7584 12
    },
c7f7584 13
    api: {
c7f7584 14
      getResolvedRoutes() {
c7f7584 15
        return ctx.options.resolver.getComputedRoutes(ctx)
c7f7584 16
      },
c7f7584 17
    },
c7f7584 18
    configureServer(server) {
c7f7584 19
      ctx.setupViteServer(server)
c7f7584 20
    },
c7f7584 21
    resolveId(id) {
c7f7584 22
      if (ctx.options.moduleIds.includes(id))
c7f7584 23
        return `${MODULE_ID_VIRTUAL}?id=${id}`
c7f7584 24
c7f7584 25
      if (routeBlockQueryRE.test(id))
c7f7584 26
        return ROUTE_BLOCK_ID_VIRTUAL
c7f7584 27
c7f7584 28
      return null
c7f7584 29
    },
c7f7584 30
    async load(id) {
c7f7584 31
      const {
c7f7584 32
        moduleId,
c7f7584 33
        pageId,
c7f7584 34
      } = parsePageRequest(id)
c7f7584 35
c7f7584 36
      if (moduleId === MODULE_ID_VIRTUAL && pageId && ctx.options.moduleIds.includes(pageId))
c7f7584 37
        return ctx.resolveRoutes()
c7f7584 38
c7f7584 39
      if (id === ROUTE_BLOCK_ID_VIRTUAL) {
c7f7584 40
        return {
c7f7584 41
          code: 'export default {};',
c7f7584 42
          map: null,
c7f7584 43
        }
c7f7584 44
      }
c7f7584 45
c7f7584 46
      return null
c7f7584 47
    },
c7f7584 48
  }
c7f7584 49
}
c7f7584 50
c7f7584 51
// https://vitejs.dev/config/
c7f7584 52
export default defineConfig({
c7f7584 53
  plugins: [
c7f7584 54
  ],
c7f7584 55
})