Skip to content

Conversation

@adamdbradley
Copy link
Contributor

@adamdbradley adamdbradley commented Oct 19, 2022

Refactor and simplify adaptors for SSR and SSG.

  • No longer automatically modifying the user's vite.config.ts
  • Add an adaptors directory to the users app
  • Adaptors include a vite.config.ts which extends the user's base config
  • Users can modify the adaptor's vite.config.ts
  • Static Site Generation is integrated into server adaptors, such as cloudflare-pages

Breaking Change

The submodule @builder.io/qwik-city/static/node has been replaced with just @builder.io/qwik-city/static, which will eventually work for both Node and Deno.

Previously, if the server did both SSR and SSG, it needed and entry for both the server (src/entry.cloudflare-pages.tsx) and the ssg build (src/entry.static.tsx). With the new adaptors, entry.static.tsx is no longer needed, and is now an option.

// adaptors/cloudflare-pages/vite.config.ts

import { cloudflarePagesAdaptor } from '@builder.io/qwik-city/adaptors/cloudflare-pages/vite';
import { extendConfig } from '@builder.io/qwik-city/vite';
import baseConfig from '../../vite.config';

export default extendConfig(baseConfig, () => {
  return {
    build: {
      ssr: true,
      rollupOptions: {
        input: ['src/entry.cloudflare-pages.tsx', 'src/entry.ssr.tsx', '@qwik-city-plan'],
      },
    },
    ssr: {
      target: 'webworker',
      noExternal: true,
    },
    plugins: [
      cloudflarePagesAdaptor({
        staticGenerate: true,
      }),
    ],
  };
});

Future Steps

With the server and static builds integrated when needed, this could allow Qwik to generate highly optimized SSR modules which would be mostly static. Mean the render function would have very little work to do on-demand since a majority of the rendering would just be static strings.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 19, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1b59252
Status: ✅  Deploy successful!
Preview URL: https://729a1b12.qwik-docs.pages.dev
Branch Preview URL: https://refactor-ssg.qwik-docs.pages.dev

View logs

@adamdbradley adamdbradley merged commit a9db0b1 into main Oct 19, 2022
@adamdbradley adamdbradley deleted the refactor-ssg branch October 19, 2022 20:28
@adamdbradley adamdbradley mentioned this pull request Oct 19, 2022
2 tasks
@nnelgxorz
Copy link
Contributor

Excited for this!

@zanettin
Copy link
Contributor

great job 🙏 thanks a lot @adamdbradley !

// TODO: Better way to get QwikManifest
const manifest: QwikManifest = (globalThis as any).QWIK_MANIFEST;
// TODO: Remove globalThis that was previously used. Left in for backwards compatibility.
const manifest: QwikManifest = (globalThis as any).QWIK_MANIFEST || qwikPlugin.api.getManifest();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is causing the error below

qwikPlugin.api.getManifest is not a function
/qwik-app/node_modules/@builder.io/qwik-city/vite/index.cjs:23909:63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants