forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ssr/ssg adaptors, starters (QwikDev#1805)
- Loading branch information
1 parent
4734e74
commit a9db0b1
Showing
107 changed files
with
1,684 additions
and
1,179 deletions.
There are no files selected for viewing
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,24 @@ | ||
## API Report File for "@builder.io/qwik-city" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
```ts | ||
|
||
import type { QwikManifest } from '@builder.io/qwik/optimizer'; | ||
import type { SymbolMapper } from '@builder.io/qwik/optimizer'; | ||
import type { SymbolMapperFn } from '@builder.io/qwik/optimizer'; | ||
|
||
// @alpha (undocumented) | ||
export function cloudflarePagesAdaptor(opts?: CloudflarePagesAdaptorOptions): any; | ||
|
||
// @alpha (undocumented) | ||
export interface CloudflarePagesAdaptorOptions { | ||
// Warning: (ae-forgotten-export) The symbol "StaticGenerateRenderOptions" needs to be exported by the entry point index.d.ts | ||
// | ||
// (undocumented) | ||
staticGenerate?: StaticGenerateRenderOptions | true; | ||
} | ||
|
||
// (No @packageDocumentation comment for this package) | ||
|
||
``` |
15 changes: 15 additions & 0 deletions
15
packages/qwik-city/adaptors/cloudflare-pages/vite/api-extractor.json
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,15 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"extends": "../../../api-extractor.json", | ||
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/adaptors/cloudflare-pages/vite/index.d.ts", | ||
"apiReport": { | ||
"enabled": true, | ||
"reportFileName": "api.md", | ||
"reportFolder": "<projectFolder>/packages/qwik-city/adaptors/cloudflare-pages/", | ||
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/adaptors/cloudflare-pages" | ||
}, | ||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/adaptors/cloudflare-pages/vite/index.d.ts" | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
packages/qwik-city/adaptors/cloudflare-pages/vite/index.ts
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,105 @@ | ||
import type { Plugin } from 'vite'; | ||
import type { QwikVitePlugin } from '@builder.io/qwik/optimizer'; | ||
import type { StaticGenerateOptions, StaticGenerateRenderOptions } from '../../../static'; | ||
import { join } from 'path'; | ||
import fs from 'fs'; | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export function cloudflarePagesAdaptor(opts: CloudflarePagesAdaptorOptions = {}): any { | ||
let qwikVitePlugin: QwikVitePlugin | null = null; | ||
let serverOutDir: string | null = null; | ||
let renderModulePath: string | null = null; | ||
let qwikCityPlanModulePath: string | null = null; | ||
|
||
async function generateBundles() { | ||
const qwikVitePluginApi = qwikVitePlugin!.api; | ||
const clientOutDir = qwikVitePluginApi.getClientOutDir()!; | ||
|
||
const serverPackageJsonPath = join(serverOutDir!, 'package.json'); | ||
const serverPackageJsonCode = `{"type":"module"}`; | ||
await fs.promises.writeFile(serverPackageJsonPath, serverPackageJsonCode); | ||
|
||
if (opts.staticGenerate) { | ||
const staticGenerate = await import('../../../static'); | ||
let generateOpts: StaticGenerateOptions = { | ||
outDir: clientOutDir, | ||
origin: process?.env?.CF_PAGES_URL || 'https://your.cloudflare.pages.dev', | ||
renderModulePath: renderModulePath!, | ||
qwikCityPlanModulePath: qwikCityPlanModulePath!, | ||
}; | ||
|
||
if (typeof opts.staticGenerate === 'object') { | ||
generateOpts = { | ||
...generateOpts, | ||
...opts.staticGenerate, | ||
}; | ||
} | ||
|
||
await staticGenerate.generate(generateOpts); | ||
} | ||
} | ||
|
||
const plugin: Plugin = { | ||
name: 'vite-plugin-qwik-city-cloudflare-pages', | ||
enforce: 'post', | ||
apply: 'build', | ||
|
||
configResolved({ build, plugins }) { | ||
qwikVitePlugin = plugins.find((p) => p.name === 'vite-plugin-qwik') as QwikVitePlugin; | ||
if (!qwikVitePlugin) { | ||
throw new Error('Missing vite-plugin-qwik'); | ||
} | ||
serverOutDir = build.outDir; | ||
|
||
if (build?.ssr !== true) { | ||
throw new Error( | ||
'"build.ssr" must be set to `true` in order to use the Cloudflare Pages adaptor.' | ||
); | ||
} | ||
|
||
if (!build?.rollupOptions?.input) { | ||
throw new Error( | ||
'"build.rollupOptions.input" must be set in order to use the Cloudflare Pages adaptor.' | ||
); | ||
} | ||
}, | ||
|
||
generateBundle(_, bundles) { | ||
for (const fileName in bundles) { | ||
const chunk = bundles[fileName]; | ||
if (chunk.type === 'chunk' && chunk.isEntry) { | ||
if (chunk.name === 'entry.ssr') { | ||
renderModulePath = join(serverOutDir!, fileName); | ||
} else if (chunk.name === '@qwik-city-plan') { | ||
qwikCityPlanModulePath = join(serverOutDir!, fileName); | ||
} | ||
} | ||
} | ||
|
||
if (!renderModulePath) { | ||
throw new Error( | ||
'Unable to fine "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?' | ||
); | ||
} | ||
if (!qwikCityPlanModulePath) { | ||
throw new Error( | ||
'Unable to fine "@qwik-city-plan" entry point. Did you forget to add it to "build.rollupOptions.input"?' | ||
); | ||
} | ||
}, | ||
|
||
async closeBundle() { | ||
await generateBundles(); | ||
}, | ||
}; | ||
return plugin; | ||
} | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export interface CloudflarePagesAdaptorOptions { | ||
staticGenerate?: StaticGenerateRenderOptions | true; | ||
} |
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,24 @@ | ||
## API Report File for "@builder.io/qwik-city" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
```ts | ||
|
||
import type { QwikManifest } from '@builder.io/qwik/optimizer'; | ||
import type { SymbolMapper } from '@builder.io/qwik/optimizer'; | ||
import type { SymbolMapperFn } from '@builder.io/qwik/optimizer'; | ||
|
||
// @alpha (undocumented) | ||
export function expressAdaptor(opts?: NetlifyEdgeAdaptorOptions): any; | ||
|
||
// @alpha (undocumented) | ||
export interface NetlifyEdgeAdaptorOptions { | ||
// Warning: (ae-forgotten-export) The symbol "StaticGenerateRenderOptions" needs to be exported by the entry point index.d.ts | ||
// | ||
// (undocumented) | ||
staticGenerate?: StaticGenerateRenderOptions | true; | ||
} | ||
|
||
// (No @packageDocumentation comment for this package) | ||
|
||
``` |
15 changes: 15 additions & 0 deletions
15
packages/qwik-city/adaptors/express/vite/api-extractor.json
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,15 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"extends": "../../../api-extractor.json", | ||
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/adaptors/express/vite/index.d.ts", | ||
"apiReport": { | ||
"enabled": true, | ||
"reportFileName": "api.md", | ||
"reportFolder": "<projectFolder>/packages/qwik-city/adaptors/express/", | ||
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/adaptors/express" | ||
}, | ||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/adaptors/express/vite/index.d.ts" | ||
} | ||
} |
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,103 @@ | ||
import type { Plugin } from 'vite'; | ||
import type { QwikVitePlugin } from '@builder.io/qwik/optimizer'; | ||
import type { StaticGenerateOptions, StaticGenerateRenderOptions } from '../../../static'; | ||
import { join } from 'path'; | ||
import fs from 'fs'; | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export function expressAdaptor(opts: NetlifyEdgeAdaptorOptions = {}): any { | ||
let qwikVitePlugin: QwikVitePlugin | null = null; | ||
let serverOutDir: string | null = null; | ||
let renderModulePath: string | null = null; | ||
let qwikCityPlanModulePath: string | null = null; | ||
|
||
async function generateBundles() { | ||
const qwikVitePluginApi = qwikVitePlugin!.api; | ||
const clientOutDir = qwikVitePluginApi.getClientOutDir()!; | ||
|
||
const serverPackageJsonPath = join(serverOutDir!, 'package.json'); | ||
const serverPackageJsonCode = `{"type":"module"}`; | ||
await fs.promises.writeFile(serverPackageJsonPath, serverPackageJsonCode); | ||
|
||
if (opts.staticGenerate) { | ||
const staticGenerate = await import('../../../static'); | ||
let generateOpts: StaticGenerateOptions = { | ||
outDir: clientOutDir, | ||
origin: process?.env?.URL || 'https://yoursitename.example.com', | ||
renderModulePath: renderModulePath!, | ||
qwikCityPlanModulePath: qwikCityPlanModulePath!, | ||
}; | ||
|
||
if (typeof opts.staticGenerate === 'object') { | ||
generateOpts = { | ||
...generateOpts, | ||
...opts.staticGenerate, | ||
}; | ||
} | ||
|
||
await staticGenerate.generate(generateOpts); | ||
} | ||
} | ||
|
||
const plugin: Plugin = { | ||
name: 'vite-plugin-qwik-city-express', | ||
enforce: 'post', | ||
apply: 'build', | ||
|
||
configResolved({ build, plugins }) { | ||
qwikVitePlugin = plugins.find((p) => p.name === 'vite-plugin-qwik') as QwikVitePlugin; | ||
if (!qwikVitePlugin) { | ||
throw new Error('Missing vite-plugin-qwik'); | ||
} | ||
serverOutDir = build.outDir; | ||
|
||
if (build?.ssr !== true) { | ||
throw new Error('"build.ssr" must be set to `true` in order to use the Express adaptor.'); | ||
} | ||
|
||
if (!build?.rollupOptions?.input) { | ||
throw new Error( | ||
'"build.rollupOptions.input" must be set in order to use the Express adaptor.' | ||
); | ||
} | ||
}, | ||
|
||
generateBundle(_, bundles) { | ||
for (const fileName in bundles) { | ||
const chunk = bundles[fileName]; | ||
if (chunk.type === 'chunk' && chunk.isEntry) { | ||
if (chunk.name === 'entry.ssr') { | ||
renderModulePath = join(serverOutDir!, fileName); | ||
} else if (chunk.name === '@qwik-city-plan') { | ||
qwikCityPlanModulePath = join(serverOutDir!, fileName); | ||
} | ||
} | ||
} | ||
|
||
if (!renderModulePath) { | ||
throw new Error( | ||
'Unable to fine "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?' | ||
); | ||
} | ||
if (!qwikCityPlanModulePath) { | ||
throw new Error( | ||
'Unable to fine "@qwik-city-plan" entry point. Did you forget to add it to "build.rollupOptions.input"?' | ||
); | ||
} | ||
}, | ||
|
||
async closeBundle() { | ||
await generateBundles(); | ||
}, | ||
}; | ||
return plugin; | ||
} | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export interface NetlifyEdgeAdaptorOptions { | ||
staticGenerate?: StaticGenerateRenderOptions | true; | ||
} |
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,24 @@ | ||
## API Report File for "@builder.io/qwik-city" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
```ts | ||
|
||
import type { QwikManifest } from '@builder.io/qwik/optimizer'; | ||
import type { SymbolMapper } from '@builder.io/qwik/optimizer'; | ||
import type { SymbolMapperFn } from '@builder.io/qwik/optimizer'; | ||
|
||
// @alpha (undocumented) | ||
export function netifyEdgeAdaptor(opts?: NetlifyEdgeAdaptorOptions): any; | ||
|
||
// @alpha (undocumented) | ||
export interface NetlifyEdgeAdaptorOptions { | ||
// Warning: (ae-forgotten-export) The symbol "StaticGenerateRenderOptions" needs to be exported by the entry point index.d.ts | ||
// | ||
// (undocumented) | ||
staticGenerate?: StaticGenerateRenderOptions | true; | ||
} | ||
|
||
// (No @packageDocumentation comment for this package) | ||
|
||
``` |
15 changes: 15 additions & 0 deletions
15
packages/qwik-city/adaptors/netlify-edge/vite/api-extractor.json
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,15 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"extends": "../../../api-extractor.json", | ||
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/adaptors/netlify-edge/vite/index.d.ts", | ||
"apiReport": { | ||
"enabled": true, | ||
"reportFileName": "api.md", | ||
"reportFolder": "<projectFolder>/packages/qwik-city/adaptors/netlify-edge/", | ||
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/adaptors/netlify-edge" | ||
}, | ||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/adaptors/netlify-edge/vite/index.d.ts" | ||
} | ||
} |
Oops, something went wrong.