Giter Site home page Giter Site logo

presite's Introduction

presite

NPM version NPM downloads CircleCI donate

Why (not) prerender?

  • It works for every single-page website
  • It requires no modification on your app code
  • It does not suite large website that heavily depends on async data, use SSR instead.

Install

npm i -g presite

# China mirror for downloading chromium
npm config set puppeteer_download_host=https://storage.googleapis.com.cnpmjs.org
npm i -g presite

Usage

presite ./path/to/your/spa

Then the generated website can be found at .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"
  }
}

By default it only prerenders path: /, you can configure routes option for more, see below:

Configure in presite.config.js

Note: You can also configuration it in presite.config.json or the presite key in package.json.

Set routes that needs prerender

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

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()

Source directory

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

presite's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar egoist avatar erasmuswill avatar

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.