#How to trigger SSG build when using Cloudflare Adapter

16 messages · Page 1 of 1 (latest)

tidal raft
#

I'm using the Cloudflare Adapter and I want to use public/_routes.json to mark some routes to be rendered at build time (SSG) while others are rendered on the server on a per request basis (SSR). My question is how to i build those pages? the build command doesn't seem to produce the needed html files in the ./dist directory

stark jackal
#

I think this is the option:
adapters/cloudflare-pages/vite.config.ts

plugins: [cloudflarePagesAdapter({
      ssg: {
        include: ['/*'],
        origin:
            (process.env.CF_PAGES_BRANCH !== 'main' ? process.env.CF_PAGES_URL : null) ??
            'https://yoursite.com',
      }
    })],
tidal raft
#

thanks for the response, now do i have to also re-declare every ssg routes also in the staticPath property of the adapter options? like so?

plugins: [cloudflarePagesAdapter(
      {
        staticPaths:[
          '/demo/flower'
        ],
        ssg: {
          include: ['/demo/flower'],
          origin:
            (process.env.CF_PAGES_BRANCH !== 'main' ? process.env.CF_PAGES_URL : null) ??
            'qwikapp-cyz.pages.dev',
        }
      }
#

also, since it's my first time experimenting with cloudflare pages, it has come to my understanding static files are delivered from their CDN not from their workers, how can i check if this is indeed the case for the indicated ssg routes?

tidal raft
#

when running npm run deploy i get this error after selecting the project
✘ [ERROR] Could not resolve "..serverentry.cloudflare-pages"

_worker.js:1:22:
  1 │ ...{ fetch } from "..\server\entry.cloudflare-pages"; export defaul...
    ╵                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can mark the path "..serverentry.cloudflare-pages" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Build failed with 1 error:

_worker.js:1:22: ERROR: Could not resolve "..serverentry.cloudflare-pages"

stark jackal
lucid burrow
stark jackal
tidal raft
#

thanks for help, i can seem to get npm run deploy to work even in an wsl enviroment. when running under wsl i keep getting asked to give a new project name and it doesn't let me choose an existing project. on windows it does let me choose an existing project but errors after upload

#

i made an issue for the error under the windows enviroment, i'm not sure i am not at fault for wsl workaround not working, i tried making a wrangler.toml file with all the config but with no success

stark jackal
#

remember that npm run build is required before npm run deploy

#

I added this to scripts:
"preview.wrangler": "qwik build && wrangler pages dev ./dist",

#

and it works for me

tidal raft
#

thanks for your input on this issue @stark jackal you've been verry helpful to me

glacial gorge
#

@tidal raft have you been successful in this? I would also like to have all my product routes served as static files from cloudflare without buring workers CPU cycles.