A SvelteKit adapter that creates a Netlify app.
If you're using adapter-auto, you don't need to install this unless you need to specify Netlify-specific options, since it's already included.
⚠️ For the time being, the latest version of adapter-netlify is at the @next tag. If you get the errorconfig.kit.adapter should be an object with an "adapt" method.
, this is a sign that you are using the wrong version (eg1.0.0-next.0
instead of1.0.0-next.9
).
npm i -D @sveltejs/adapter-netlify@next
You can then configure it inside of svelte.config.js
:
import adapter from '@sveltejs/adapter-netlify';
export default {
kit: {
adapter: adapter({
// if true, will split your app into multiple functions
// instead of creating a single one for the entire app
split: false
})
}
};
Then, make sure you have a netlify.toml file in the project root. This will determine where to write static assets based on the build.publish
settings, as per this sample configuration:
[build]
command = "npm run build"
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"
.
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.
During compilation, redirect rules are automatically appended to your _redirects
file. (If it doesn't exist yet, it will be created.) That means:
[[redirects]]
innetlify.toml
will never match as_redirects
has a higher priority. So always put your rules in the_redirects
file._redirects
shouldn't have any custom "catch all" rules such as/* /foobar/:splat
. Otherwise the automatically appended rule will never be applied as Netlify is only processing the first matching rule.
- Create your Netlify HTML form as described here, e.g. as
/routes/contact.svelte
. (Don't forget to add the hiddenform-name
input element!) - Netlify's build bot parses your HTML files at deploy time, which means your form must be prerendered as HTML. You can either add
export const prerender = true
to yourcontact.svelte
to prerender just that page or set thekit.prerender.force: true
option to prerender all pages. - If your Netlify form has a custom success message like
<form netlify ... action="/success">
then ensure the corresponding/routes/success.svelte
exists and is prerendered.
Netlify Functions 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:
[build]
command = "npm run build"
publish = "build"
[functions]
directory = "functions"
node_bundler = "esbuild"