Skip to content

Commit

Permalink
create website starter
Browse files Browse the repository at this point in the history
  • Loading branch information
deebloo committed Oct 7, 2024
1 parent b19b6ce commit db2983b
Show file tree
Hide file tree
Showing 12 changed files with 690 additions and 11 deletions.
551 changes: 546 additions & 5 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"license": "MIT",
"workspaces": [
"packages/**",
"integration/**"
"integration/**",
"website"
],
"scripts": {
"prepare": "husky"
Expand Down
21 changes: 16 additions & 5 deletions packages/ssr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ applicator.apply(document, [])
## Vite

```TS
import { Applicator. NoopTemplateCache, FileSysTemplateLoader } from '@joist/ssr';
import { Applicator, NoopTemplateCache, FileSysTemplateLoader } from '@joist/ssr';
import { defineConfig } from 'vite';

const applicator = new Applicator(
Expand All @@ -35,13 +35,24 @@ const applicator = new Applicator(
export default defineConfig({
plugins: [
{
name: 'Web Component SSR',
transformIndexHtml: {
enforce: "pre",
transform(html) {
return applicator.apply(html, ['my-element', 'my-dropdown']);
order: 'pre',
handler(html) {
return applicator.apply(html, ['joist-header', 'joist-nav']);
}
},
handleHotUpdate({ file, server }) {
if (file.includes('elements') && (file.endsWith('.html') || file.endsWith('.css'))) {
console.log(`${file} updated...`);

server.ws.send({
type: 'full-reload',
path: '*'
});
}
}
}
],
]
});
```
8 changes: 8 additions & 0 deletions website/elements/joist-header/joist-header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:host {
display: contents;
}

header {
padding: 1rem;
background: blue;
}
1 change: 1 addition & 0 deletions website/elements/joist-header/joist-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<header>Joist</header>
12 changes: 12 additions & 0 deletions website/elements/joist-header/joist-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { element } from '@joist/element';

@element({
tagName: 'joist-header'
})
class JoistHeaderElement extends HTMLElement {
constructor() {
super();
}
}

export { JoistHeaderElement };
8 changes: 8 additions & 0 deletions website/elements/joist-nav/joist-nav.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:host {
display: contents;
}

nav {
display: flex;
flex-direction: column;
}
4 changes: 4 additions & 0 deletions website/elements/joist-nav/joist-nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<nav>
<a href="">Getting Started</a>
<a href="">API</a>
</nav>
8 changes: 8 additions & 0 deletions website/elements/joist-nav/joist-nav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { element } from '@joist/element';

@element({
tagName: 'joist-nav'
})
class JoistNavElement extends HTMLElement {}

export { JoistNavElement };
39 changes: 39 additions & 0 deletions website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>

<body>
<style>
body {
margin: 0;
padding: 0;
}

* {
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Open Sans',
'Helvetica Neue',
sans-serif;
}
</style>

<joist-header></joist-header>

<joist-nav></joist-nav>

<script type="module" src="./elements/joist-header/joist-header.ts"></script>
<script type="module" src="./elements/joist-nav/joist-nav.ts"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@joist/website",
"type": "module",
"scripts": {
"start": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^5.4.7"
}
}
34 changes: 34 additions & 0 deletions website/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Applicator, NoopTemplateCache, FileSysTemplateLoader } from '@joist/ssr';
import { defineConfig } from 'vite';

const applicator = new Applicator(
new NoopTemplateCache(),
new FileSysTemplateLoader(
(tag) => `elements/${tag}/${tag}.html`,
(tag) => `elements/${tag}/${tag}.css`
)
);

export default defineConfig({
plugins: [
{
name: 'Web Component SSR',
transformIndexHtml: {
order: 'pre',
handler(html) {
return applicator.apply(html, ['joist-header', 'joist-nav']);
}
},
handleHotUpdate({ file, server }) {
if (file.includes('elements') && (file.endsWith('.html') || file.endsWith('.css'))) {
console.log(`${file} updated...`);

server.ws.send({
type: 'full-reload',
path: '*'
});
}
}
}
]
});

0 comments on commit db2983b

Please sign in to comment.