-
Hi, i'm trying to setup shoelace to use with Astro and do not understand how do i use components. What should i suppose to do next? import '@shoelace-style/shoelace/dist/components/button/button.js'; // [ERROR] MutationObserver is not defined
---
import SlButton from '@shoelace-style/shoelace/dist/components/button/button.js';
<SlButton>Click me</SlButton> // // [ERROR] MutationObserver is not defined
---
<sl-button>Click me</sl-button> // just div created should i additionally configure vite somehow or should i import components in another way? Please help me to figure this out |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
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({
+ vite: {
resolve: {
alias: [
{
find: /\/assets\/icons\/(.+)/,
replacement: `${iconsPath}/$1`,
},
],
},
build: {
rollupOptions: {
// external: /^lit/,
plugins: [],
},
},
plugins: [
viteStaticCopy({
targets: [
{
src: iconsPath,
dest: "assets",
},
],
}),
],
},
});
|
Beta Was this translation helpful? Give feedback.
-
I made a starter kit that works without the config. https://github.com/b-d-m-p/astro-shoelace-starter-kit-blog |
Beta Was this translation helpful? Give feedback.
Solved this by importin via <script>, not in frontmatter:
also configured vite in astro, according to this example https://stackblitz.com/edit/vitejs-vite-jfzwow?file=vite.config.ts&terminal=dev