Want to quickly get started building your own project with Prismic and SvelteKit? This project includes basic configurations and nothing else. The project includes one Rich Text Slice, a homepage, and a dynamic page.
To start a new project using this starter, run the following commands in your terminal:
npx @slicemachine/init@latest --starter sveltekit-starter-prismic-minimal
The commands will do the following:
When you're ready to start your project, run the following command:
npm run dev
To edit the content of this project, go to prismic.io/dashboard, click on the repository for this website, and start editing.
To create a page, click on the green pencil icon, then select Page.
Pages are made of Slices. You can add and rearrange Slices to your pages.
Your new page will be accessible by its URL, but it won't appear on the website automatically. To let users discover it, add it to the navigation.
This website is preconfigured with Prismic. It has three Prismic packages installed:
@prismicio/clientprovides helpers for fetching content from Prismic
@prismicio/svelteprovides Svelte components for rendering content from Prismic
These packages are already integrated and employed in this app. Take a look at the code to see how they're used.
There are two steps to rendering content from Prismic in your SvelteKit project:
Here are some of the files in your project that you can edit:
src/lib/prismicio.js- This file includes configuration for
@prismicio/clientand exports useful API helpers.
src/routes/+layout.svelte- This is your layout component.
src/routes/+page.svelte- This is the app homepage. It queries and renders a page document with the UID (unique identifier) "home" from the Prismic API.
src/routes/[uid]/+page.svelte- This is the page component, which queries and renders a page document from your Prismic repository based on the UID.
src/lib/slices/*/index.svelte- Each Slice in your project has an
index.sveltefile that renders the Slice component. Edit this file to customize your Slices.
These are important files that you should leave as-is:
src/routes/slice-simulator/+page.svelte- Do not edit or delete this file. This file simulates your Slice components in development.
src/lib/slices/- This directory contains Slice components, which are generated programmatically by Slice Machine. To customize a Slice template, you can edit the Slice's index.js file. To add Slices, delete Slices, or edit Slice models, use Slice Machine (more info below).
To put your project online, see Deploy your SvelteKit App.
This project includes an application called Slice Machine, which generates models for your Custom Types and Slices. Slice Machine stores the models locally in your codebase, so you can save and version them. It also syncs your models to Prismic. To learn how to use Slice Machine, read Model Content in SvelteKit.
If you change or add to your Custom Types, you'll need to update your route handling to match. To learn how to do that, read Define Paths in SvelteKit.
For the official Prismic documentation, see Prismic's guide for SvelteKit or the technical references for the installed Prismic packages.
Copyright 2013-2023 Prismic <email@example.com> (https://prismic.io) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.