Giter Club home page Giter Club logo

staticit's Introduction

Static-it

Build Status

Staticit - Introduction

Whether you want to increase performance of your web application or improve SEO. Generally you have 2 options, use SSR (Server Side Rendering) or SSG (Static Site Generation). SSR can be cumbersome and you will need a server to host it.

SSG is relatively simple and a good alternative. Some frameworks have this feature out of the box some don't, some are bloated and you may want a simpler solution. Here comes the Staticit!

Staticit is a improved version of a small library called react-spa-prerender. Under the hood it uses express and puppeteer to generate static files.

Since it's standalone it will work with any build tool and any front-end framework that supports routing.

How it works?

  • Serves the web application from build directory with express.
  • Renders & generates desired routes with puppeteer.
  • Reformats all generated HTML files with prettier so they'll be pretty ๐Ÿฅฐ.

Install

- Latest LTS Node.js is recommended.

  • With npm:
$ npm install -D staticit
  • With yarn:
$ yarn add --dev staticit
  • With pnpm:
$ pnpm install -D staticit

Usage

Create a file called .staticit.json in your project root directory. For minimal configuration add the following lines.

{
  "routes": ["/", "/about"],
  "outDir": "./dist",
  "port": 8080
}

- If you are going to build your application in an automated environment, for example with a CI tool. You should pass the --no-sandbox flag to puppeteer: launchOpts or you might get errors since most of them are running inside of a container with root user. (Ref)

"scripts": {
  ...
  "postbuild": "staticit"
}

References

JSON Reference

Option Default Description
routes [] Array of routes that you want to pre-render & generate static files.
outDir ./dist Relative path to the build directory of your application.
port 8080 The port where the static server will serve your web application for the puppeteer.
puppeteer: launchOpts {} Generic launch options that can be passed when launching puppeteer browser.
puppeteer: waitForOpts {} Timeout options for puppeteer browser.

--

CLI Reference

Option Description
--disable-prettier Disables formatting HTML files with prettier.
-c, --config To use with different config file name.

Examples

License

This repository is licensed under the MIT License.

staticit's People

Contributors

alcadramin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

armelgeek

staticit's Issues

Err: Invalid access of discarded(invalid, deleted) uWS.HttpResponse/SSLHttpResponse

Hey there,

first of all I would like to compliment you for having thought of this workaround that eases integrating pre-rendered static sites in frontend frameworks.

Stack:

  • Vue 3 + Vite (Scaffolded using Vite CLI)
  • Node 16
  • M1 Macbook Air 2020

Now onto the issue: I am trying to static-ify a bunch of routes in my frontend project.
But sadly there is this following error that appears in 80% of cases:

image

The special thing about this is, that it works some of the time. Most of the time it does not.

Cheers and keep up the good work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.