[ ] Update astro.config.mjs to include Vite build config that automatically bundles all components in src/web-components.
[ ] Reference the bundled components in package.sql.ts and other SQLPage dependencies and Astro pages via script tags.
This approach keeps our Ornament components integrated with minimal configuration changes, ensuring they are easily accessible via https://www.surveilr.com/js/wc/component.js.
Implement the following to integrate Ornament-based web components into our existing Astro site using Astro's built-in Vite configuration.
First, install Ornament to create web components:
npm install @sirpepe/ornament
Add components to src/web-components. Here's an example component:
// src/web-components/my-greeter.ts
import { define, attr, string, number, connected, reactive } from "@sirpepe/ornament";
@define("my-greeter")
class MyGreeter extends HTMLElement {
#shadow = this.attachShadow({ mode: "open" });
@attr(string()) accessor name = "Anonymous";
@attr(number({ min: 0 })) accessor age = 0;
@reactive()
@connected()
greet() {
this.#shadow.innerHTML = `Hello! My name is ${this.name}, my age is ${this.age}`;
}
}
Add a Vite configuration to bundle your web components:
We need to make many reusable web components available to
surveilr web-ui
SQLPage pages. Use Ornament web component infrastructure.src/web-components
.astro.config.mjs
to include Vite build config that automatically bundles all components insrc/web-components
.package.sql.ts
and other SQLPage dependencies and Astro pages via script tags.This approach keeps our Ornament components integrated with minimal configuration changes, ensuring they are easily accessible via
https://www.surveilr.com/js/wc/component.js
.Implement the following to integrate Ornament-based web components into our existing Astro site using Astro's built-in Vite configuration.
First, install Ornament to create web components:
Add components to
src/web-components
. Here's an example component:Add a Vite configuration to bundle your web components:
Reference the compiled JavaScript files in our SQLPage and Astro pages: