-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[feat] use Netlify internal functions directory for generated functions #2113
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
Changes from all commits
e228bbc
7ecb000
2bcbeb7
b730c54
bb5939d
b10fcb9
4fe2486
12e3766
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sveltejs/adapter-netlify': patch | ||
| --- | ||
|
|
||
| Deploy generated Netlify entrypoint to the internal functions directory. This allows it to co-exist with other Netlify functions. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ yarn.lock | |
| .svelte-kit | ||
| .cloudflare | ||
| .pnpm-debug.log | ||
| .netlify | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
| node_modules | ||
| /.svelte | ||
| /build | ||
| /functions | ||
| /.netlify/functions* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"type":"commonjs"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,16 @@ export default { | |
| }; | ||
| ``` | ||
|
|
||
| Then, make sure you have a [netlify.toml](https://docs.netlify.com/configure-builds/file-based-configuration) file in the project root. This will determine where to write static assets and functions to based on the `build.publish` and `build.functions` settings, as per this sample configuration: | ||
| Then, make sure you have a [netlify.toml](https://docs.netlify.com/configure-builds/file-based-configuration) file in the project root. This will determine where to write static assets based on the `build.publish` settings, as per this sample configuration: | ||
|
|
||
| ```toml | ||
| [build] | ||
| command = "npm run build" | ||
| publish = "build/publish/" | ||
| functions = "build/functions/" | ||
|
Member
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 know if we can just remove this. Where will it put functions then? We put this here on purpose so that all output would show up under
Member
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. Or at least if we're going to remove this line, should we also remove the Perhaps what we could do is maintain the old behavior and use the directories in these files if they are present and if they are not then we use the directory you're specifying as a default
Contributor
Author
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. The functions will be in
Contributor
Author
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. If they user isn't using the Netlify CLI then presumably this won't be an issue anyway, as it wouldn't be using the Netlify preset when building locally as the auto-detection won't trigger it.
Contributor
Author
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. Though I suppose the user could have manually specified the preset.
Member
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. Ok, thanks for clarifying and being patient as I come up-to-speed on Netlify stuff. I'm on board with your plan. Lets always output to
Contributor
Author
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. OK, so skip the CLI detection entirely?
Member
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. What would be the benefit of CLI detection? If we're not using the Netlify CLI, I'm assuming that any code
Contributor
Author
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. Correct. I'll update the PR.
Contributor
Author
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. OK, I've updated the PR as follows:
One thing I'd like to suggest for a follow-up PR is that |
||
| publish = "build" | ||
| ``` | ||
|
|
||
| If the `netlify.toml` file or the `build.publish` value is missing, a default value of `"build"` will be used. Note that if you have set the publish directory in the Netlify UI to something else then you will need to set it in `netlify.toml` too, or use the default value of `"build"`. | ||
|
|
||
| ## Netlify alternatives to SvelteKit functionality | ||
|
|
||
| You may build your app using functionality provided directly by SvelteKit without relying on any Netlify functionality. Using the SvelteKit versions of these features will allow them to be used in dev mode, tested with integration tests, and to work with other adapters should you ever decide to switch away from Netlify. However, in some scenarios you may find it beneficial to use the Netlify versions of these features. One example would be if you're migrating an app that's already hosted on Netlify to SvelteKit. | ||
|
|
@@ -53,6 +54,20 @@ During compilation a required "catch all" redirect rule is automatically appende | |
| 2. Netlify's build bot parses your HTML files at deploy time, which means your form must be [prerendered](https://kit.svelte.dev/docs#ssr-and-javascript-prerender) as HTML. You can either add `export const prerender = true` to your `contact.svelte` to prerender just that page or set the `kit.prerender.force: true` option to prerender all pages. | ||
| 3. If your Netlify form has a [custom success message](https://docs.netlify.com/forms/setup/#success-messages) like `<form netlify ... action="/success">` then ensure the corresponding `/routes/success.svelte` exists and is prerendered. | ||
|
|
||
| ### Using Netlify Functions | ||
|
|
||
| [Netlify Functions](https://docs.netlify.com/functions/overview/) can be used alongside your SvelteKit routes. If you would like to add them to your site, you should create a directory for them and add the configuration to your `netlify.toml` file. For example: | ||
|
|
||
| ```toml | ||
| [build] | ||
| command = "npm run build" | ||
| publish = "build" | ||
|
|
||
| [functions] | ||
| directory = "functions" | ||
| node_bundler = "esbuild" | ||
| ``` | ||
|
|
||
| ## Advanced Configuration | ||
|
|
||
| ### esbuild | ||
|
|
@@ -77,7 +92,8 @@ The default options for this version are as follows: | |
| ```js | ||
| { | ||
| entryPoints: ['.svelte-kit/netlify/entry.js'], | ||
| outfile: `pathToFunctionsFolder/render/index.js`, | ||
| // This is Netlify's internal functions directory, not the one for user functions. | ||
| outfile: '.netlify/functions-internal/__render.js', | ||
| bundle: true, | ||
| inject: ['pathTo/shims.js'], | ||
| platform: 'node' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| [build] | ||
| command = "npm run build" | ||
| publish = ".svelte-kit/netlify/build/" | ||
| functions = ".svelte-kit/netlify/functions/" | ||
| publish = "build" |
Uh oh!
There was an error while loading. Please reload this page.