TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Fast Jekyll Alternative in TypeScript with JSX

13 点作者 sbjs超过 1 年前

3 条评论

sbjs超过 1 年前
Also, why haven't we just standardized on JSX being sugar for {tag,attrs,children} literals? Then it can be manipulated at runtime however anyone wants, and we would have had so much fewer problems with basically everything around it.
nwsm超过 1 年前
Any kind of documentation or README would be great
评论 #37836234 未加载
sbjs超过 1 年前
So, couple facts about this SSG&#x27;s design that nobody will ever read:<p>1. It&#x27;s hyper-efficient with how it reloads modules, to do the absolutely least amount of work necessary. If a file hasn&#x27;t changed, it&#x27;s not touched. If a .ts&#x2F;.tsx file hasn&#x27;t changed and nothing depends on it, its exports aren&#x27;t touched. If it hasn&#x27;t changed but something has that depend son it, it&#x27;s function isn&#x27;t recompiled, only its exports are re-exported by re-running it.<p>2. Everything in src&#x2F; is normal, but everything under site&#x2F; is loaded by src&#x2F; and compiled via sucrase, and run in its own runtime. This is what allows the psuedo module system above to be so efficient. It&#x27;s also what makes the JSX feature so simple and yet fast.<p>3. The JSX syntax essentially compiles down to an object like {tag:string, attrs:object, children:any[]}, which can be manipulated at runtime. This allows for script&#x2F;style&#x2F;link hoisting and de-duplicating, which means you can put a css link in a component that&#x27;s used multiple times in the site, but only loaded in the HTML once, and pulled up into the head element. It&#x27;s turned into a string by walking the tree and adding to an array and joining it when done. I think it can be improved. For a while it was in the site&#x2F; runtime but I saw no benefit to that.<p>4. Import just uses require under the hood, and importing any file claims a dependency on it which reloads your file whenever the depended-upon file changes, whether the one you&#x27;re importing is a normal ts&#x2F;tsx module or a resource file (css, js, jpg, etc).<p>5. Importing a file tree returns a list of every file under that tree recursively, including future dependencies. So if you `import files from &#x27;.&#x2F;images&#x2F;&#x27;;` then it will reload the file containing this import not only when a file changes in .&#x2F;images&#x2F;foo&#x2F;bar&#x2F; but also when one is added or removed from it. This is really helpful in reloading when e.g. new data files are added. And the fact that it returns a flat list of &quot;absolute&quot; file paths (relative to site&#x2F;) makes it easy to operate on and filter through.<p>6. When you import a static resource (jpg, css, etc), it returns {path:string, content:Buffer} as well as claiming a dependency on it, so that you can e.g. use the path in a href, or examine its buffer and do something with it, etc. Eventually I want to reintroduce the concept of dynamically generated routes, e.g. given a font dir, you can currently use the Font component, but it genereates a script tag; it&#x27;d be better if it introduced a link tag that can be cached by the browser.<p>7. Components with this are super cool and easy to use, but there&#x27;s a lot of low-hanging fruit. I&#x27;m in no rush to see what kind of things I can do with it, but it&#x27;s already picking up speed in the past few weeks. One of my next challenges for myself is figuring out how to use the dynamic static resource concept in point 6 to generate unique IDs for pseudo-scoped-css, similar to what react styled-components and all them did.
评论 #37841186 未加载