Everything you need to build a Svelte project, powered by create-svelte.
This project is configured to use SvelteKit with two different adapters: an auto adapter for local development and the Cloudflare Pages adapter for deployment. Follow the instructions below to run the project in a development environment or prepare it for deployment on Cloudflare Pages.
- Node.js installed on your machine
- A Cloudflare Pages account for deployment
First, clone the repository and install the dependencies:
git clone <your-repository-url>
cd <your-project-directory>
npm install
This project uses Vitest for unit testing. The tests are centralized in the /tests directory and are configured to run automatically on every build pushed to Cloudflare Pages.
You can also run the tests manually using the following commands:
This command will start the test runner and watch for any file changes, re-running tests automatically.
npm testThis command runs the entire test suite once and exits. This is the same command used in the Cloudflare Pages build process.
npm run test:ciTo run the tests and see a detailed coverage report in your terminal, use:
npx vitest run --coverageTo run the project locally using the auto adapter, simply start the development server:
npm run dev
This will serve your application on http://localhost:3000 by default. The auto adapter is selected automatically for local development.
Create a launch.json in the .vscode folder and paste the following configuration:
{
// server - runs dev server in dev mode, allowing for breakpoints on server side code.
// chrome - uses Chrome and allows for breakpoints for client side code.
// Both (Client & Server) - debugging for both the server side and the client side.
"version": "0.2.0",
"configurations": [
{
"name": "server",
"request": "launch",
"runtimeArgs": ["run-script", "dev"],
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"type": "node",
"console": "integratedTerminal"
},
{
"type": "chrome",
"request": "launch",
"name": "chrome",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}"
}
],
"compounds": [
{
"name": "Both (Client & Server)",
"configurations": ["server", "chrome"]
}
]
}
To prepare your application for deployment on Cloudflare Pages, you need to set an environment variable to switch to the Cloudflare Pages adapter. This can be done in two ways:
When configuring your project on Cloudflare Pages, set the following environment variable:
- Name: ADAPTER
- Value: cloudflare
This tells your application to use the Cloudflare Pages adapter for the build process on Cloudflare.
If you wish to test the Cloudflare Pages adapter locally, you can run:
npm run build:cloudflare
Note: The built site may not function exactly as expected locally because it's optimized for Cloudflare Pages.
After setting the environment variable in your Cloudflare Pages project settings, push your changes to the connected Git repository. Cloudflare Pages will automatically build and deploy your site using the settings configured.