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

statically

v1.0.1

Published

A simple tool for build static website from urls.

Downloads

2

Readme

Statically

Install

$ npm install statically

How it works

Statically is a simple tool that allows you to build static website from urls.

Let's say you want to build an app or a website, and you use a template engine like lit-html or Preact for example.Your code will look like something like the one in lit-html-example folder. If you run webpack it will generate a dist folder containing an index.html file and index.entry.js. This is perfectly fine and it will work, in fact if you run:

$ http-server dist

you will see the site up and running. So what's the problem? Well there are 2 main problems with it:

  • Client Rendering
  • Network Request for data that could be statically rendered, which will results in a less performant website.

Since in this case we are just rendering some static data, it would be much better to prerender them as much as possible, and remove the scripts that are not necessary anymore as well, so we do not have to request them over the network on runtime.

Basically we should go from something like:

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>Example</h1>

    <div id="hello"></div>
    <div id="github"></div>

    <script data-remove src="./index.static.js"></script>
</body>
</html>

Note: The html nodes with the attribute data-remove will be removed automatically by the tool.

to something like:

<!-- index.html -->
<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>Example</h1>

    <div id="hello"><div>Hello Kevin!</div></div>
    <div id="github"><p>Github username: Pachito Marco Calabrese is located in Denmark and is a a telecommunication engineer with the passion for mixing web and embedded systems and is known on GitHub as pmcalabrese, he has 30 repos</p></div>

    <!-- note there is no script here -->

</body></html>

This is nice, beacuse we can carry on developing with a comfortable rendering template like lit-html and prerendering (for example just before deploy) for good performance and SEO.

Statically will allow you to do that with ease. All you need is a simple config file. The config file Statically.config.js will contains the list of urls that need to became a file.

Let's have a look at the lit-html-example folder.

// staticly.config.js
const path = require("path");

const urls = [{
    url: "http://localhost:8081",
    dist_file: path.resolve(process.cwd() + "/../../public-static/index.html")
}]

module.exports = urls;

After create the config file

$ cd lit-html-example
$ webpack

this will generate a dist folder, lets serve the folder with http-server tool like so:

$ http-server -p 8081 dist

Now we can run staticly. Remember that the port in the config file must match the port of the server (in this specifi example i chose 8081)

$ staticly --config ../staticly.config.js

Final note: lit-html is just an example, this tool is appliacable for any render lib, like React Preact etc.

CLI usage

you can use with a config file

$ staticly --config ../staticly.config.js

or passing an url and a file

staticly --url www.google.com --file google.html