DEV Community

Cover image for How to integrate shadcn-svelte into the editable.website template
Benson Mwaura
Benson Mwaura

Posted on

How to integrate shadcn-svelte into the editable.website template

Follow these steps to integrate shadcn-svelte into the editable.website template. This guide assumes you have a basic understanding of SvelteKit and Node.js.

Step 1: Set Up Your Project

  • Clone the **Editable.Website Template**: Start by cloning the editable.website repository to your local machine:

bash

git clone https://github.com/michael/editable-website.git
cd editable-website
Enter fullscreen mode Exit fullscreen mode
  • Install Dependencies: Install the necessary dependencies for your project:

bash

pnpm install
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Environment Variables

Copy .env.example to .env and configure your database and admin password.


Step 3: Seed the Database

  • Note: Make sure you have sqlite3 installed on your system. If not, you can install it from here.

  • Seed your database using:

bash

sqlite3 data/db.sqlite3 < sql/schema.sql
Enter fullscreen mode Exit fullscreen mode

Step 4: Run the Development Server

bash

pnpm run dev
Enter fullscreen mode Exit fullscreen mode

Step 5: Create a jsconfig.json

Since the editable.websiteseems to be opted-out of TypeScript, to configure import aliases, create a jsconfig.json file:

bash

touch jsconfig.json
Enter fullscreen mode Exit fullscreen mode

jsconfig.json

json

{
    "compilerOptions": {
        "paths": {
          "$lib/*": ["./src/lib/*"]
        }
      }
}
Enter fullscreen mode Exit fullscreen mode

Step 6: Setup Path Aliases

  • If you are not using the default alias $lib, update your svelte.config.js file to include those aliases.

svelte.config.js

const config = {
      // ... other config
      kit: {
        // ... other config
        alias: {
          $lib: "src/lib",
          "$lib/*": "src/lib/*",
          $components: "src/lib/components",
          "$components/*": "src/lib/components/*",
          $utils: "src/lib/utils",
          "$utils/*": "src/lib/utils/*"
        }
      }
};
Enter fullscreen mode Exit fullscreen mode

Step 7: Install Compatible Prettier Version

To fix the warning about peer dependencies for prettier-plugin-tailwindcss and prettier-plugin-svelte:

  • Install Compatible Prettier Versions: Create a new dev dependency using a compatible version for svelte:

bash

pnpm install --save-dev prettier@^2.0
Enter fullscreen mode Exit fullscreen mode

*Use *npm alias: This allows you to install multiple versions of Prettier:
bash

pnpm install --save-dev prettier-2@npm:prettier@^2.0.0 prettier-3@npm:prettier@^3.0.0
Enter fullscreen mode Exit fullscreen mode
  • Adjust Scripts: Update your npm scripts in package.json to use the specific Prettier versions:

package.json

json

"scripts": {
      "format:svelte": "prettier-2 --write 'src/**/*.{js,svelte}'",
      "format:other": "prettier-3 --write 'src/**/*.{js,ts,css,md,json}'"
}
Enter fullscreen mode Exit fullscreen mode

Step 8: Run the CLI

bash

pnpm dlx shadcn-svelte@latest init
Enter fullscreen mode Exit fullscreen mode

Step 9: Configure components.json

You will be asked a few questions to configure components.json:

bash

      Would you like to use TypeScript (recommended)? › Yes
      Which style would you like to use? › Default
      Which color would you like to use as base color? › Slate
      Where is your global CSS file? › src/app.css
      Where is your tailwind.config.[cjs|js|ts] located? › tailwind.config.js
      Configure the import alias for components: › $lib/components
      Configure the import alias for utils: › $lib/utils
Enter fullscreen mode Exit fullscreen mode

That's It

You can now start adding components to your project.

bash

pnpm dlx shadcn-svelte@latest add button
Enter fullscreen mode Exit fullscreen mode

The command above will add the Button component to your project. You can then import it like this:

svelte

      <script lang="ts">
      import { Button } from "$lib/components/ui/button";
      </script>

      <Button>Click me</Button>
Enter fullscreen mode Exit fullscreen mode

This guide should provide a solid foundation for integrating shadcn-svelte into the editable.website template. If you have any specific questions or need further assistance, feel free to checkout the docs for shadcn-svelte and the editable.website repo.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay