https://github.com/posrix/prerender-seo
Prerender Javascript rendered pages for SEO
https://github.com/posrix/prerender-seo
phantomjs prerender react vue
Last synced: 6 months ago
JSON representation
Prerender Javascript rendered pages for SEO
- Host: GitHub
- URL: https://github.com/posrix/prerender-seo
- Owner: posrix
- Created: 2017-12-06T15:20:14.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T05:21:15.000Z (over 1 year ago)
- Last Synced: 2025-03-25T10:42:45.291Z (10 months ago)
- Topics: phantomjs, prerender, react, vue
- Language: HTML
- Homepage: https://www.npmjs.com/package/prerender-seo
- Size: 240 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# prerender-seo
Prerender HTML files using [Puppeteer](https://github.com/GoogleChrome/puppeteer).
## Install
```bash
npm i prerender-seo -D
```
## Usage
``` js
const path = require('path')
const prerender = require('prerender-seo')
const files = [
'/index.html'
]
prerender(
path.resolve(__dirname, './dist'),
files,
{
// options
}
)
```
## Test
The test case use a [vue-cli](https://github.com/vuejs/vue-cli) generated project
``` bash
npm run test
```
## Options
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`sourceDir`**|`{String}`|`-`|Source directory of static files|
|**`files`**|`{Array}`|`-`|HTML Files to prerender|
|**`options.destDir`**|`{String}`|`*_prerender`|Destination directory to store the result|
|**`options.proxyTable`**|`{Array}`|`[]`|Proxy to forward any http request that match the config|
|**`options.navigationTimeout`**|`{Number}`|`30000`|Define the timeout of any navigation operations|
|**`options.resourceInterception`**|`{Array}`|`[]`|Define the regular expression of any resource will be aborted|
### `sourceDir`
```js
prerender(
path.resolve(__dirname, '../dist')
)
```
### `files`
```js
prerender(
files: [
'index.html',
'about.html',
'product.html'
]
)
```
### `options.destDir`
Define the destination directory. If you want to replace the source directory, just set the same path as `sourceDir`.
```js
prerender(
path.resolve(__dirname, '../dist'),
files: [
'index.html',
'about.html',
'product.html'
],
{
destDir: path.resolve(__dirname, '../dist')
}
)
```
### `options.proxyTable`
```js
prerender(
path.resolve(__dirname, '../dist'),
files: [
'index.html',
'about.html',
'product.html'
],
{
proxyTable: {
context: '/api',
proxy: {
host: 'example.com',
port: '80',
protocol: 'http'
}
}
}
)
```
### `options.navigationTimeout`
Define the timeout after which any navigation operations will stop trying. (in milli-secs)
```js
prerender(
path.resolve(__dirname, '../dist'),
files: [
'index.html',
'about.html',
'product.html'
],
{
navigationTimeout: 60000
}
)
```
### `options.resourceInterception`
Define the regular expression to match any resource url will be aborted before request. The left hand in the array is `RegExp` pattern, the right hand is `RegExp` flag.
```js
prerender(
path.resolve(__dirname, '../dist'),
files: [
'index.html',
'about.html',
'product.html'
],
{
resourceInterception: [
['hm.baidu.com', 'g'],
['/api/tokenAttach', 'g']
]
}
)
```