@projectevergreen/astro-wcc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # astro-wcc
2
+
3
+ An [Astro](https://astro.build/) integration for SSR Web Components using [WCC](https://github.com/ProjectEvergreen/wcc).
4
+
5
+ ## Usage
6
+
7
+ 1. Install the plugin into your Astro project
8
+ ```sh
9
+ $ npm i astro-wcc
10
+ ```
11
+ 1. Then add it to your Astro configuration file
12
+ ```js
13
+ import { defineConfig } from 'astro/config';
14
+ import astroWcc from 'astro-wcc';
15
+
16
+ export default defineConfig({
17
+ integrations: [ astroWcc() ]
18
+ });
19
+ ```
20
+
21
+ ## Caveats
22
+
23
+ - Currently assumes `<x-${tagName}>` maps to _src/components/${tagName}.js_
24
+ - Client hints (e.g. `<x-greeting client:visible>`) are not supported
package/TODO.md ADDED
@@ -0,0 +1,15 @@
1
+ 1. [ ] Create as npm package
2
+ 1. [ ] Client hints - track as issue
3
+ ```
4
+ <x-greeting client:visible></x-greeting>
5
+ ```
6
+ 1. [ ] auto mapping imports - track as issue
7
+ 1. [ ] additional plugin configurations? - track as question
8
+ ```js
9
+ injectScript("head-inline", readFileSync(new URL("./client-shim.min.js", import.meta.url), { encoding: "utf-8" }));
10
+
11
+ // https://github.com/thepassle/custom-elements-ssr/blob/master/astro.js#L3
12
+ updateConfig({
13
+ vite: getViteConfiguration()
14
+ });
15
+ ```
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export default function astroWCC() {
2
+ return {
3
+ name: "wcc-ssr",
4
+ hooks: {
5
+ "astro:config:setup": ({ updateConfig, addRenderer, injectScript }) => {
6
+ addRenderer({
7
+ name: "astro-wcc",
8
+ serverEntrypoint: "astro-wcc/server.js"
9
+ });
10
+ }
11
+ }
12
+ }
13
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@projectevergreen/astro-wcc",
3
+ "version": "0.1.0",
4
+ "description": "An Astro integration for SSR Web Components using WCC",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "author": "Owen Buckley <owen@thegreenhouse.io>",
8
+ "homepage": "https://github.com/ProjectEvergreen/astro-wcc#readme",
9
+ "license": "MIT",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ProjectEvergreen/astro-wcc.git"
16
+ },
17
+ "keywords": [
18
+ "Astro",
19
+ "WCC",
20
+ "Web Components",
21
+ "SSR"
22
+ ],
23
+ "peerDependencies": {
24
+ "astro": "^4.8.6"
25
+ },
26
+ "dependencies": {
27
+ "wc-compiler": "^0.13.0"
28
+ }
29
+ }
package/server.js ADDED
@@ -0,0 +1,22 @@
1
+ import { renderFromHTML } from 'wc-compiler';
2
+
3
+ const CWD_URL = new URL(`file://${process.cwd()}/`);
4
+
5
+ async function check(tagName) {
6
+ return tagName.indexOf('-') > 0;
7
+ }
8
+
9
+ async function renderToStaticMarkup(tagName, props, slots) {
10
+ console.log('renderToStaticMarkup', { tagName, props, slots })
11
+ const suffix = tagName.split('-')[1];
12
+ const attributes = Object.entries(props).map(([key, value]) => ` ${key}="${value}"`).join('');
13
+
14
+ const { html } = await renderFromHTML(`<${tagName} ${attributes}></${tagName}>`, [
15
+ new URL(`./src/components/${suffix}.js`, CWD_URL)
16
+ ]);
17
+ console.log({ html });
18
+
19
+ return { html };
20
+ }
21
+
22
+ export default { check, renderToStaticMarkup };