slice-machine-ui - v1.0
Overview
slice-machine-ui
is the core package for Prismic’s local development tool, Slice Machine.
Dependencies and requirements
slice-machine-ui
v1.0 depends on an adapter to work with your framework. There are currently three officially-supported adapters:
@slicemachine/adapter-next
for Next.js@slicemachine/adapter-nuxt
for Nuxt@slicemachine/adapter-sveltekit
for SvelteKit@slicemachine/adapter-nuxt2
for Nuxt 2 (legacy)
Installation
Slice Machine offers an init
script to take care of most boilerplate and configuration.
init
script
In your project, run this command:
npx @slicemachine/init@latest
This command will do the following:
- Create a new Prismic repository or let you specify an existing one.
- Add a
slicemachine
script topackage.json
. - Create an
slicemachine.config.json
configuration file containing your API endpoint and the location of your slice library. - Detect your framework (Next.js).
- Install dependencies:
@prismicio/client
,@prismicio/slice-simulator-react
,@prismicio/react
,@prismicio/next
, andslice-machine-ui
. - Create a
pages/slice-simulator.js|jsx|tsx
file.
Manual install
To manually install Slice Machine, follow these steps:
-
Create a new Prismic repository from the Prismic dashboard.
-
In your project, add a
slicemachine
script to yourpackage.json
:
{
scripts: {
+ "slicemachine": "start-slicemachine"
}
}
- Create a
slicemachine.config.json
file at the root of your project and paste in this information:
{
"repositoryName": "example-prismic-repo",
"adapter": "@slicemachine/adapter-next",
"libraries": ["./slices"]
}
- Update the
repositoryName
property to your repository name and theadapter
property with your framework’s Slice Machine adapter.
Usage
Launch Slice Machine
slice-machine-ui
locally runs a development tool called Slice Machine. Run this command to launch Slice Machine:
npm run slicemachine
This will launch Slice Machine on localhost and show the URL in your terminal. Open the URL in your browser.
Configure slicemachine.config.json
The slicemachine.config.json
file contains an object that contains the following properties:
repositoryName Required | The repository name for your repository (e.g.
|
libraries Required | An array of directories where Slice Machine can find
slices, relative to the project’s root director. By
default, this is |
adapter Required | The name of the npm package to use as an adapter for
your framework (e.g. |
apiEndpoint | The endpoint for your repository. Slice Machine
automatically uses the correct API endpoint for your
repository by default, based on |