Build with Svelte
Create a Svelte project with the Azion CLI, build it, and deploy it to an Azion domain.
With the Azion CLI, you start a Svelte project from a SvelteKit template, build it, and deploy it. After the deploy, the project runs on Azion and answers on an Azion domain.
A Svelte project on Azion has two parts: static files in a storage bucket and a function that holds the server code. An application delivers the files and runs the function. For the other frameworks that Azion builds, refer to Frameworks compatibility.
Prerequisites
- An Azion account. To create one, refer to Create an account.
- The Azion CLI, installed and logged in. To set it up, refer to Azion CLI quickstart.
- Node.js 18 or later, and npm.
- A terminal and a code editor.
Deploy the project
You create the project with azion init, build it with azion build, and send it to Azion with azion deploy.
To create the project, pass a name to azion init. Select Svelte in the preset picker, then a template in the template picker:
The -y flag installs the project dependencies. The --auto flag skips the questions about a local development server and a deploy. For the questions that the command asks without these flags, refer to Azion CLI init. The picker lists three Svelte templates. With SvelteKit Boilerplate, the output is:
The command writes the project to a my-app folder. The azion.config.mjs file in that folder sets the svelte preset and declares the resources of the deploy:
- A storage bucket that receives
./build, with read-only access for workloads. - A function built from the SvelteKit server code.
- Application rules that deliver files under
/_app/immutableand files with static extensions from the bucket. - An application rule named
Execute Svelte Functionthat runs the function.
For every setting in that file, refer to azion.config.js.
To build the project, go to its folder and run azion build:
Azion Bundler runs the SvelteKit build with the svelte preset and the sveltejs/adapter-azion adapter. The function entry comes from .svelte-kit/azion/_worker.js:
The build prints a warning about ./.svelte-kit/tsconfig.json and still ends with Your Application was built successfully.
To deploy the project, run azion deploy in the project folder:
The CLI sends the project to Azion and opens a Console page that tracks the deploy. The CLI also prints the URL of that page, for when no browser opens. At the end, it prints the URL of the project’s domain. For the full output and the flags that change a deploy, refer to Azion CLI deploy.
To test the project on your computer first, refer to Azion CLI dev. To deploy a Svelte project that you already have, run azion link in its folder and select svelte in the preset list. For more information, refer to Azion CLI link.
Check the project
When azion deploy ends, it prints the URL of the project’s Azion domain, in the form https://xxxxxxxxxx.map.azionedge.net. Open the URL in a browser to see the Svelte project.
The first deploy can take several minutes to answer from every location; later deploys take about two minutes. A location that does not have the project yet returns a 404 page with the text There's nothing here yet. When you see that page, wait, and then load the URL again.