- 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.
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
presite ./path/to/your/spa
Then the generated website can be found at .presite
folder.
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:
Note: You can also configuration it in presite.config.json
or the presite
key in package.json
.
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 specific ms or dom element to appear:
module.exports = {
wait: 3000
// Or wait for an element to appear
// wait: '#comments'
}
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()
module.exports = {
baseDir: './path/to/your/spa'
}
By default it outputs to .presite
folder in current directory.
module.exports = {
outDir: '.presite'
}
Run presite --help
.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
presite © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).
Website · GitHub @egoist · Twitter @_egoistlily