Skip to content

rossrobino/domco

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

domco is a Vite plugin that adds the following functionality.

domco is under development and has not reached version 1.0, please file any issues on GitHub.

Overview

In contrast to other static site generators, which often require familiarization with various template file types, domco presents a refreshing solution. It enables you to utilize HTML, CSS, and JavaScript, and work undeterred by the shifts in the landscape of server side JavaScript tooling.

One key feature domco provides is the use of browser APIs on the server through the usage of jsdom.

Take for instance, fetching data from a CMS and having it rendered on a page. Your website already handles this task smoothly in the browser.

// client side JavaScript
const res = await fetch("https://my-cms...");
const data = await res.json();
const article = document.querySelector("article");
article.innerHtml = data.html;

Now, what if you could take this same code, and run it at build time? Move this to a server context, you usually run into ReferenceError: document is not defined.

Most frameworks require you to learn a new strategy for rendering on the server, for example using JSX, or a markdown file with front-matter variables.

// ReactServerComponent.jsx
const ServerComponent = () => {
    const res = await fetch("https://my-cms...");
    const data = await res.json();
    return <article>{data.html}</article>;
};

export default ServerComponent;

These strategies work well, but also create another abstraction on top of what you already know. They also have some limitations, for example, what if you want to modify the result of some markdown after it gets processed into HTML? It quickly becomes difficult without something like document.querySelector.

"JavaScript is great at manipulating the DOM." --- The Primeagen

With domco you do not need learn a new API, UI framework, or even language to update HTML at build time. You can just make updates to the HTML using familiar browser APIs within a build function, ensuring less JavaScript get shipped to each user.

// src/+config.ts
import type { Config } from "domco";

export const config: Config = {
	build: async ({ document }) => {
		const res = await fetch("https://my-cms...");
		const data = await res.json();
		const article = document.querySelector("article");
		article.innerHtml = data.html;
	},
};

domco aims to provide many of the features and developer experience of modern frameworks without having to learn a new language.