Skip to content

Shoelace with Astro (vitejs) not importing components #2031

Answered by skorphil
skorphil asked this question in Help
Discussion options

You must be logged in to vote

Solved this by importin via <script>, not in frontmatter:

---
import { setBasePath } from "@shoelace-style/shoelace/dist/utilities/base-path.js";
setBasePath("dist/assets");
---

<script>
  import("@shoelace-style/shoelace/dist/themes/dark.css");
  import("@shoelace-style/shoelace/dist/components/button/button.js");
</script>
...
<sl-button>click me</sl-button>

also configured vite in astro, according to this example https://stackblitz.com/edit/vitejs-vite-jfzwow?file=vite.config.ts&terminal=dev

// astro.config.mjs

+ import { viteStaticCopy } from "vite-plugin-static-copy";
+ const iconsPath = "node_modules/@shoelace-style/shoelace/dist/assets/icons";

export default defineConfig({
+ vit…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@b-d-m-p
Comment options

@b2m9
Comment options

@skorphil
Comment options

Answer selected by skorphil
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants