Created
May 17, 2024 11:38
-
-
Save guiseek/fe9259e0a37508628d5f41c2b9eedbe5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const App = () => { | |
const title = "TSX Vanilla"; | |
return ( | |
<> | |
<h1>{title}</h1> | |
</> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { App } from "./app"; | |
import "./style.scss"; | |
app.appendChild(App()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"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"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference types="vite/client" /> | |
declare const app: HTMLDivElement; | |
declare namespace JSX { | |
interface Element extends HTMLElement {} | |
type IntrinsicElements = { | |
[K in keyof HTMLElementTagNameMap]: Partial<HTMLElementTagNameMap[K]>; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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