npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tsx-pack

v0.0.5

Published

Dead Simple Static Site Generator with JSX and TypeScript

Downloads

11

Readme

tsx-pack

Dead Simple Static Site Generator

Write your website in TSX files and convert them to static HTML files with CSS and JS dependencies optimally bundled inline

Features ✨

  • Write Type safe component templates with the power of Typescript and JSX
  • Generates optimized pages with CSS & JS minified and inlined in HTML document to maximize the core web vital metrics of the page.

Getting Started 🚀

bootstrap project by running the below command

npx degit MananTank/tsx-pack/templates/tsx my-website-name

cd my-website-name
npm i

Writing Components 🧑🏻‍💻

Components are just regular functions that return JSX Element.

If a component has a dependency on a JS or CSS file, it must be declared via useCSS and useJS hooks

import { useCSS, useJS } from 'tsx-pack'

type FooProps = {
  foo: string
}

export function Foo(props: FooProps) {
  useCSS('./blog.css')
  useJS('./blog.js')

  return <div> {props.foo} </div>
}

Rendering to HTML 🎨

render the component with render method, second argument is the relative path at which you would like to put the generated file. ( make sure that folders you specify in this path already exist)

<CSS /> and <JS /> components represent inlined CSS and JS collected by the tsx-pack for the page.

import { render, CSS, JS } from 'tsx-pack'
import { Foo } from './components/Foo'

function FooPage() {
  return (
    <html>
      <head>
        <CSS />
        <title> Foo </title>
      </head>
      <body>
        <Foo />
        <JS />
      </body>
    </html>
  )
}

render(<FooPage />, '../../public/foo.html')

Development 🛠

Working on a Page

If you are working on page/Home/index.tsx page, run this command

npm run dev src/pages/Home/index.tsx

With this, Everytime you make a change inside the src folder, foo.tsx will run and generate the HTML file

Starting Live Dev Server

in a new instance of the terminal, run this command to have a live dev server that automatically reloads the page when you make a change in the source code

npm run dev-server

Creating Production Build 👷‍♂️🧰

Build All Pages

make sure all the pages you want to generate are listed in the build.ts file.

Then run this command to generate all the files

npm run build-all

Build particular page

If you only want to build a particular page - pages/Home/index.tsx for example, use this command:

npm run build src/pages/Home/index.tsx