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

spa-to-static-site-generator

v1.1.0

Published

A Node.js module for generating static HTML files from a Single Page Application (SPA) using Puppeteer.

Downloads

8

Readme

Static Site Generator

npm version

A Node.js module designed to generate static HTML files from a Single Page Application (SPA) (or any other type of web page) using Puppeteer. It opens each specified URL in a headless browser, captures the fully rendered HTML content, and saves it as static files. This can be particularly useful for SEO purposes, caching, and improving the initial load performance of your web application.

Files Created

For each URL in the provided list, the script creates the following:

  • Directory Structure: A directory that corresponds to the path of the URL.
  • index.html: An HTML file containing the fully rendered content of the page.

For example, if the URLs are https://example.com/, https://example.com/page1, https://example.com/page2, etc., the script will create:

output/
├── index.html
├── page1/
│   └── index.html
├── page2/
│   └── index.html
├── about/
│   └── index.html
└── contact/
    └── index.html

Installation

npm install static-site-generator

Usage

  1. Create your SPA build locally or deploy it to production
  2. Create a list of URLs to process.
  3. Generate the static files (ensure that all assets are correctly linked and served. Please note, this script generates only html files).
  4. Create a script file, for example: generate-static-site.js
  5. Update the code in generate-static-site.js:
    const generateStaticSite = require('spa-to-static-site-generator');
       
    const urls = [
        'http://example.com/page1',
        'http://example.com/page2',
        // Add more URLs as needed
    ];
       
    const outputDir = 'output';
       
    generateStaticSite(urls, outputDir)
        .then(() => {
            console.log('Static site generation complete.');
        })
        .catch(error => {
            console.error('Error generating static site:', error);
        });
  6. Run the script node generate-static-site.js
  7. Serve the Static Files: Deploy the generated static files to your web server or hosting service, ensuring that all assets are correctly linked and served.
  8. If you are using NGINX, prepare your config:
    location / {
        # Other options
        expires        max;
        try_files      $uri $uri/ /index.html;
    }

API

generateStaticSite(urls, outputDir, [timeout], [retries])

Generate static HTML files from a list of URLs.

  • urls (Array): Array of URLs to process.
  • outputDir (string): Directory to save generated HTML files.
  • [timeout] (number, optional): Navigation timeout in milliseconds. Default is 60000.
  • [retries] (number, optional): Number of retry attempts on failure. Default is 3.
  • [makeScreenshots] if true it will create screenshots of each page

License

MIT