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

generate-static-site

v0.0.12

Published

🤖 Generate a Static HTML Site from your Local Files or a Web Server. (Sometimes referred as server side rendering or pre-rendering)

Downloads

29

Readme

Videos

Watch a simple introduction video on YouTube.

Watch an example using the Wanilla library.

Usage

By default generate-static-site will pre-render all scripts*. This means the scripts will be executed twice. Once in pre-render (SSR) and once on the client-side.

If you wish some scripts to only be pre-rendered or only be client-side rendered, see the examples below:

*except a block list of common files like, google-analytics, facebook.net, doubleclick.net, stats.wp.com etc.

<!-- will be executed during SSR and client side -->
<script src="/js/script.js"></script>

<!-- will not be executed during SSR -->
<script noSSR src="/js/script.js"></script>

<!-- will only be executed during SSR (will be removed in the final site) -->
<script SSROnly src="/js/script.js"></script>

<!-- inline scripts with "noSSR" have no effect (include the script with src="" instead) -->
<script noSSR>
  // DON'T DO THIS!
</script>

<!-- will only be executed during SSR (will be removed in the final site) -->
<script SSROnly>
  // YOU CAN DO THIS
</script>

<!-- dynamically decide what to do -->
<script>
  if (window.isSRR) {
    // executed in SSR
  }

  if (!window.isSRR) {
    // executed on the client
  }
</script>

Inline CSS

In order to inline a stylesheet, add the inline attribute:

<link inline rel="stylesheet" href="/css/style.css" />

Express Middleware

Coming soon.

CLI

Generate Static Site

USAGE
  npx generate-static-site <input> <output> <entries...> [options]

ARGUMENTS
  input                   FOLDER or URL
  output                  FOLDER
  entries                 PATHS, separated by spaces

OPTIONS
  --allow=<regex...>      List of allowed resources as RegEx, separated by commas
  --block=<regex...>      List of blocked resources as RegEx, separated by commas
  --exec=<string>         Execute custom JavaScript
  --no-copy               Don't copy any resources
  --no-follow             Don't follow internal links
  --no-javascript         Disable JavaScript

GUI
  Run "npx generate-static-site" without arguments or options to display an easy to use step-by-step graphical interface

CLI Examples

# renders all html files insider /src to /www
# (needs a index.html file inside /src)
npx generate-static-site

# optional use @latest (from time to time)
npx generate-static-site@latest

# renders "workspace files" to www
npx generate-static-site . www

# renders /site/one to www
npx generate-static-site site/one www

# renders https://my-website.com to www
npx generate-static-site https://my-website.com www

# renders http://localhost:8080 to www
# (starts rendering with the /contact page)
npx generate-static-site http://localhost:8080 www contact

# allows to only fetch .js files during ssr
[...] --allow=/\.js$/

# prevent only google analytics from being executed during rendering
[...] --block=/google-analytics\.com/

# execute custom JavaScript (remove title)
[...] --exec="const title = document.getElementById('title');if (title) title.remove();"

# execute custom JavaScript (change background color)
[...] --exec="const wrapper = document.getElementById('wrapper');if (wrapper) wrapper.style.backgroundColor = 'blue';"

Better documentation available soon as part of the Licht project.