Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created May 17, 2024 11:38
Show Gist options
  • Save guiseek/fe9259e0a37508628d5f41c2b9eedbe5 to your computer and use it in GitHub Desktop.
Save guiseek/fe9259e0a37508628d5f41c2b9eedbe5 to your computer and use it in GitHub Desktop.
export const App = () => {
const title = "TSX Vanilla";
return (
<>
<h1>{title}</h1>
</>
);
};
export function factory(
tagOrFn: string | (() => Element),
attrs: object,
...children: Node[]
) {
const isTag = typeof tagOrFn === "function";
console.log(isTag);
const element = isTag ? tagOrFn() : document.createElement(tagOrFn);
element.append(...children);
return Object.assign(element, attrs);
}
export function fragment() {
console.log('fragment');
const template = document.createElement("template");
return template.content.cloneNode(true);
}
import { App } from "./app";
import "./style.scss";
app.appendChild(App());
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"jsx": "preserve",
"jsxFactory": "factory",
"jsxFragmentFactory": "fragment"
},
"include": ["src"]
}
/// <reference types="vite/client" />
declare const app: HTMLDivElement;
declare namespace JSX {
interface Element extends HTMLElement {}
type IntrinsicElements = {
[K in keyof HTMLElementTagNameMap]: Partial<HTMLElementTagNameMap[K]>;
};
}
import { defineConfig } from "vite";
export default defineConfig({
esbuild: {
jsxFactory: "factory",
jsxFragment: "fragment",
jsxInject: `import { factory, fragment } from '/src/jsx'`,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment