Skip to content

Commit

Permalink
fix(vercel): [vercel-edge adapter] allow to use the node target (Qw…
Browse files Browse the repository at this point in the history
…ikDev#4361)

* [vercel-edge adapter] allow to use the `node` target

this allow customers to use process.env in their apps (through dependencies)
see https://github.com/orgs/vercel/discussions/2385

I added it as a config option so we can gradually make customers
migrate. I don't want their apps to break so it's opt in for now.

* WIP

---------

Co-authored-by: Miško Hevery <[email protected]>
  • Loading branch information
Schniz and mhevery authored Oct 19, 2023
1 parent e899cf2 commit cdcf684
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
],
"kind": "Interface",
"content": "```typescript\nexport interface VercelEdgeAdapterOptions extends ServerAdapterOptions \n```\n**Extends:** ServerAdapterOptions\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [outputConfig?](#) | | boolean | <p>_(Optional)_ Determines if the build should auto-generate the <code>.vercel/output/config.json</code> config.</p><p>Defaults to <code>true</code>.</p> |\n| [staticPaths?](#) | | string\\[\\] | _(Optional)_ Manually add pathnames that should be treated as static paths and not SSR. For example, when these pathnames are requested, their response should come from a static file, rather than a server-side rendered response. |\n| [vcConfigEntryPoint?](#) | | string | <p>_(Optional)_ The <code>entrypoint</code> property in the <code>.vc-config.json</code> file. Indicates the initial file where code will be executed for the Edge Function.</p><p>Defaults to <code>entry.vercel-edge.js</code>.</p> |\n| [vcConfigEnvVarsInUse?](#) | | string\\[\\] | <p>_(Optional)_ The <code>envVarsInUse</code> property in the <code>.vc-config.json</code> file. List of environment variable names that will be available for the Edge Function to utilize.</p><p>Defaults to <code>undefined</code>.</p> |",
"content": "```typescript\nexport interface VercelEdgeAdapterOptions extends ServerAdapterOptions \n```\n**Extends:** ServerAdapterOptions\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [outputConfig?](#) | | boolean | <p>_(Optional)_ Determines if the build should auto-generate the <code>.vercel/output/config.json</code> config.</p><p>Defaults to <code>true</code>.</p> |\n| [staticPaths?](#) | | string\\[\\] | _(Optional)_ Manually add pathnames that should be treated as static paths and not SSR. For example, when these pathnames are requested, their response should come from a static file, rather than a server-side rendered response. |\n| [target?](#) | | 'webworker' \\| 'node' | <p>_(Optional)_ Define the <code>target</code> proeprty in the <code>ssr</code> property in the <code>vite.config.ts</code> file.</p><p>Defaults to <code>webworker</code> for not having a breaking change. But <code>node</code> will become the default in an upcoming release.</p> |\n| [vcConfigEntryPoint?](#) | | string | <p>_(Optional)_ The <code>entrypoint</code> property in the <code>.vc-config.json</code> file. Indicates the initial file where code will be executed for the Edge Function.</p><p>Defaults to <code>entry.vercel-edge.js</code>.</p> |\n| [vcConfigEnvVarsInUse?](#) | | string\\[\\] | <p>_(Optional)_ The <code>envVarsInUse</code> property in the <code>.vc-config.json</code> file. List of environment variable names that will be available for the Edge Function to utilize.</p><p>Defaults to <code>undefined</code>.</p> |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/adapters/vercel-edge/vite/index.ts",
"mdFile": "qwik-city.verceledgeadapteroptions.md"
}
Expand Down
13 changes: 7 additions & 6 deletions packages/docs/src/routes/api/qwik-city-vite-vercel/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export interface VercelEdgeAdapterOptions extends ServerAdapterOptions
**Extends:** ServerAdapterOptions
| Property | Modifiers | Type | Description |
| -------------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [outputConfig?](#) | | boolean | <p>_(Optional)_ Determines if the build should auto-generate the <code>.vercel/output/config.json</code> config.</p><p>Defaults to <code>true</code>.</p> |
| [staticPaths?](#) | | string[] | _(Optional)_ Manually add pathnames that should be treated as static paths and not SSR. For example, when these pathnames are requested, their response should come from a static file, rather than a server-side rendered response. |
| [vcConfigEntryPoint?](#) | | string | <p>_(Optional)_ The <code>entrypoint</code> property in the <code>.vc-config.json</code> file. Indicates the initial file where code will be executed for the Edge Function.</p><p>Defaults to <code>entry.vercel-edge.js</code>.</p> |
| [vcConfigEnvVarsInUse?](#) | | string[] | <p>_(Optional)_ The <code>envVarsInUse</code> property in the <code>.vc-config.json</code> file. List of environment variable names that will be available for the Edge Function to utilize.</p><p>Defaults to <code>undefined</code>.</p> |
| Property | Modifiers | Type | Description |
| -------------------------- | --------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [outputConfig?](#) | | boolean | <p>_(Optional)_ Determines if the build should auto-generate the <code>.vercel/output/config.json</code> config.</p><p>Defaults to <code>true</code>.</p> |
| [staticPaths?](#) | | string[] | _(Optional)_ Manually add pathnames that should be treated as static paths and not SSR. For example, when these pathnames are requested, their response should come from a static file, rather than a server-side rendered response. |
| [target?](#) | | 'webworker' \| 'node' | <p>_(Optional)_ Define the <code>target</code> proeprty in the <code>ssr</code> property in the <code>vite.config.ts</code> file.</p><p>Defaults to <code>webworker</code> for not having a breaking change. But <code>node</code> will become the default in an upcoming release.</p> |
| [vcConfigEntryPoint?](#) | | string | <p>_(Optional)_ The <code>entrypoint</code> property in the <code>.vc-config.json</code> file. Indicates the initial file where code will be executed for the Edge Function.</p><p>Defaults to <code>entry.vercel-edge.js</code>.</p> |
| [vcConfigEnvVarsInUse?](#) | | string[] | <p>_(Optional)_ The <code>envVarsInUse</code> property in the <code>.vc-config.json</code> file. List of environment variable names that will be available for the Edge Function to utilize.</p><p>Defaults to <code>undefined</code>.</p> |
[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/adapters/vercel-edge/vite/index.ts)
1 change: 1 addition & 0 deletions packages/qwik-city/adapters/vercel-edge/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function vercelEdgeAdapter(opts?: VercelEdgeAdapterOptions): any;
export interface VercelEdgeAdapterOptions extends ServerAdapterOptions {
outputConfig?: boolean;
staticPaths?: string[];
target?: 'webworker' | 'node';
vcConfigEntryPoint?: string;
vcConfigEnvVarsInUse?: string[];
}
Expand Down
15 changes: 13 additions & 2 deletions packages/qwik-city/adapters/vercel-edge/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export function vercelEdgeAdapter(opts: VercelEdgeAdapterOptions = {}): any {
config.build?.outDir || join('.vercel', 'output', 'functions', '_qwik-city.func');
return {
resolve: {
conditions: ['webworker', 'worker'],
conditions:
opts.target === 'webworker'
? ['edge-light', 'worker', 'browser', 'module', 'main']
: ['webworker', 'worker'],
},
ssr: {
target: 'webworker',
target: opts.target === 'webworker' ? 'webworker' : 'node',
noExternal: true,
},
build: {
Expand Down Expand Up @@ -127,6 +130,14 @@ export interface VercelEdgeAdapterOptions extends ServerAdapterOptions {
* server-side rendered response.
*/
staticPaths?: string[];

/**
* Define the `target` proeprty in the `ssr` property in the `vite.config.ts` file.
*
* Defaults to `webworker` for not having a breaking change. But `node` will become the default
* in an upcoming release.
*/
target?: 'webworker' | 'node';
}

/** @public */
Expand Down

0 comments on commit cdcf684

Please sign in to comment.