-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] adapter module #2285
[feat] adapter module #2285
Changes from all commits
cbfd2cf
f94fbe8
11b99fc
8fde219
f9bff84
09d007c
a76784b
17a9bbe
409b239
09cf6a9
6f50f5b
b07e677
f069539
61741f1
4abc0a2
6cb5be2
8fd0c4c
e0602fc
e84a688
fa20353
88d541a
e1af57c
d44975b
9dff930
9ab01b5
15f6149
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,17 @@ export default function (options) { | |
|
||
The types for `Adapter` and its parameters are available in [types/config.d.ts](https://github.com/sveltejs/kit/blob/master/packages/kit/types/config.d.ts). | ||
|
||
Within the `adapt` method, there are a number of things that an adapter should do: | ||
|
||
- Clear out the build directory | ||
- Output code that: | ||
- Calls `init` | ||
- Converts from the platform's request to a [SvelteKit request](#hooks-handle), calls `render`, and converts from a [SvelteKit response](#hooks-handle) to the platform's | ||
- Globally shims `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper for platforms that can use `node-fetch` | ||
Within the `adapt` method, an adapter should: | ||
|
||
- Clear out the build directory before anything else | ||
- Import `{ appResolver }` from `@sveltejs/kit/adapter` | ||
- Pass in `appResolver()` to esbuild plugins for build options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think all adapters call esbuild, do they? Or at least it seems like it shouldn't be required if you don't need bundling. E.g. there's a ticket where esbuild causes a failure if you're trying to use TypeScript reflection, so perhaps we'd want to make it an option in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any other way to include the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- Import `app` from `@sveltejs/kit/app` | ||
- Call `app.init()` as early as possible | ||
- Convert from the platform's request to a [SvelteKit request](#hooks-handle), call `app.render()`, and convert from a [SvelteKit response](#hooks-handle) to the platform's | ||
- Globally shim `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper for platforms that can use `node-fetch` | ||
- Bundle the output to avoid needing to install dependencies on the target platform, if desired | ||
- Call `utils.prerender` | ||
- Prerender static pages by calling `utils.prerender()` | ||
- Put the user's static files and the generated JS/CSS in the correct location for the target platform | ||
|
||
If possible, we recommend putting the adapter output under the `build/` directory with any intermediate output placed under `'.svelte-kit/' + adapterName`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const host: string; | ||
export const path: string; | ||
export const port: number; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { join } from 'path'; | ||
|
||
/** @type {import('@sveltejs/kit/adapter').AppResolver} */ | ||
export function appResolver() { | ||
return { | ||
name: '@sveltejs/esbuild-plugin-app-resolver', | ||
setup(build) { | ||
build.onResolve({ filter: /@sveltejs\/kit\/app/ }, (args) => ({ | ||
path: join(args.resolveDir, '../output/server/app.js') | ||
ignatiusmb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})); | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked having this line because it separates what the adapter itself is doing vs what is being done by the code that it outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the separation is nice, but it looks awkward to have nested lists in the site. I don't remember Sapper or Svelte docs with this types of list, not visibly at least, and the styles doesn't look quite right. We can probably achieve better separation with headings and/or numbered list.