All Projects → egoist → Presite

egoist / Presite

Licence: mit
A static site generator based on Puppeteer.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Presite

Photo Blog
The Photo Blog Application based on Laravel 5 and Vue.js 2 + Prerender
Stars: ✭ 55 (-80.36%)
Mutual labels:  spa, prerender
react-seo-friendly-spa-template
React PWA/SPA template initially scaffolded with CRA (Create React App) and configured for SEO. Makes use of prerendering and other techniques/packages in order to achieve a perfect "Lighthouse Score".
Stars: ✭ 24 (-91.43%)
Mutual labels:  spa, prerender
vue-seo-friendly-spa-template
Vue.js PWA/SPA template initially scaffolded with vue-cli and configured for SEO. Makes use of prerendering and other techniques/packages in order to achieve a perfect "Lighthouse Score".
Stars: ✭ 41 (-85.36%)
Mutual labels:  spa, prerender
Prerender Spa Plugin
Prerenders static HTML in a single-page application.
Stars: ✭ 7,018 (+2406.43%)
Mutual labels:  spa, prerender
parcel-plugin-prerender
No description or website provided.
Stars: ✭ 42 (-85%)
Mutual labels:  spa, prerender
ChRIS store ui
UI for the ChRIS Store
Stars: ✭ 47 (-83.21%)
Mutual labels:  spa
Universal Nest
Nest + Angular Universal = ❤️ by @TrilonIO
Stars: ✭ 258 (-7.86%)
Mutual labels:  prerender
modular-styles
Extract CSS into CSS Modules for any language!
Stars: ✭ 25 (-91.07%)
Mutual labels:  spa
web
🧱 Write your website in pure Swift with power of webassembly. DOM, CSS and all the WebAPIs are available out of the box.
Stars: ✭ 44 (-84.29%)
Mutual labels:  spa
Ios Pwa Wrapper
An iOS Wrapper application to create a native iOS App from an offline-capable Progressive Web App.
Stars: ✭ 268 (-4.29%)
Mutual labels:  spa
Vanillajs Spa
a simple SPA in vanilla js
Stars: ✭ 265 (-5.36%)
Mutual labels:  spa
generator-elm-app
A generator for generating basic template of Elm app with routing.
Stars: ✭ 16 (-94.29%)
Mutual labels:  spa
wordpress-day-spa
Example Vue.js-powered SPA running in the WordPress Admin with vue-router and vue-loader
Stars: ✭ 18 (-93.57%)
Mutual labels:  spa
Auth0 React
Auth0 SDK for React Single Page Applications (SPA)
Stars: ✭ 261 (-6.79%)
Mutual labels:  spa
spa-bus
🔥Tools for multilevel components to pass values in any SPA
Stars: ✭ 15 (-94.64%)
Mutual labels:  spa
Create React App Buildpack
⚛️ Heroku Buildpack for create-react-app: static hosting for React.js web apps
Stars: ✭ 3,161 (+1028.93%)
Mutual labels:  spa
englishextra.github.io
English Grammar for Russian-Speakers, a PWA website + SPA
Stars: ✭ 19 (-93.21%)
Mutual labels:  spa
Android Pwa Wrapper
Android Wrapper to create native Android Apps from offline-capable Progressive Web Apps
Stars: ✭ 265 (-5.36%)
Mutual labels:  spa
auth0-jquery-samples
Auth0 Integration Samples for jQuery
Stars: ✭ 14 (-95%)
Mutual labels:  spa
web development and api design
Code for the PG6301 course on Web Development and API Design
Stars: ✭ 51 (-81.79%)
Mutual labels:  spa

presite

NPM version NPM downloads donate

Why Presite?

Presite is an alternative to static site generators like Gatsby, Next.js and Nuxt.js etc, the difference is that it uses Puppeteer to prerender websites instead of relying on server-side rendering.

Install

npm i -g presite

Note that Presite relies on Chrome (or Chromium) browser on your machine, so you need to ensure it's installed before running Presite.

Usage

presite ./path/to/your/site

Presite is supposed to work with existing single-page applications, first you use something like Create React App, Vue CLI, Parcel or Vite to create a production build of your app, then use Presite to pre-render the website to static HTML files.

Pre-rendered website will be generated into .presite folder.

Examples

with Create React App
{
  "scripts": {
-    "build": "react-scripts build"
+    "build": "react-scripts build && presite ./build"
  }
}
with Vue CLI
{
  "scripts": {
-    "build": "vue-cli-service build"
+    "build": "vue-cli-service build && presite ./dist"
  }
}
with Poi
{
  "scripts": {
-    "build": "poi build"
+    "build": "poi build && presite ./dist"
  }
}
with Vite
{
  "scripts": {
-    "build": "vite build"
+    "build": "vite build && presite ./dist"
  }
}

That's it, Presite prerender all pages of your website without any configuration!

Run presite --help for all CLI flags.

Non-HTML pages

Presite also supports rendering non-HTML pages like XML or JSON pages, simply create files ending with .xml.js or .json.js, let's say you have a feed.json.js:

import { createJSONFeed } from './somewhere/create-json-feed'

export default async () => {
  const posts = await fetch('/api/my-posts').then((res) => res.json())
  return createJSONFeed(posts)
}

You can export a function that resolves to a string or JSON object, then Presite will output this page as feed.json.

These pages are evaluated in browser in a <script type="module"> tag, so you can use the import keyword.

Using presite.config.js

Many CLI flags can be stored in a configuration file, it's totaly optional but if you need one, it's there for you.

Besides presite.config.js, you can also use presite.config.json or the presite key in package.json.

Set routes that needs prerender

If some of your pages are not referenced by other pages, you can manually specify them here:

module.exports = {
  routes: ['/', '/about'],
}

Note that in most cases you won't need this option, Presite automatically find all same-site <a> elements on the pages and prerender all of them.

If you want to fetch routes asynchronously, use async/await:

module.exports = {
  async routes() {
    const routes = await fetchRoutesFromSomeWhere()
    return routes
  },
}

Wait

Wait specific ms or dom element to appear:

module.exports = {
  wait: 3000,
  // Or wait for an element to appear
  // wait: '#comments'
}

Maunally set ready state

Instead of using wait you can manually tell when the app is ready:

module.exports = {
  manually: true,
}

Then you can call window.snapshot in your app when its contents are ready:

window.snapshot && window.snapshot()

To use a custom global variable name, set it to a string instead:

module.exports = {
  manually: `__my_snapshot__`,
}

Now you should call window.__my_snapshot__() instead.

Access Puppeteer browser page

Access the page instance, for example, to expose some functions from Node.js to browser:

module.exports = {
  async onBrowserPage(page) {
    await page.exposeFunction('md5', (content) => md5(content))
  },
}

Filter out link to be crawled

To prevent link (from <a> elements) to be crawled, you could use the linkFilter option:

module.exports = {
  // Returns `true` to keep, `false` otherwise
  linkFilter(url) {
    // Ignore URLs ending with .xml
    return !url.endsWith('.xml')
  },
}

Source directory

This is the same as using CLI presite ./path/to/your/spa:

module.exports = {
  baseDir: './path/to/your/spa',
}

Output directory

By default it outputs to .presite folder in current directory.

module.exports = {
  outDir: '.presite',
}

CLI options

Run presite --help.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

presite © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

Website · GitHub @egoist · Twitter @_egoistlily

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].