Package Exports
- server-push-generator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (server-push-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Server Push Generator
Generate HTTP/2 Server Push link headers from generated static HTML.
Install
npm add server-push-generator
You can replace npm with yarn if needed
Usage
const spg = require('server-push-generator')
spg({
cwd: 'path/to/generated/html/files/dir',
urlTransformer: file => `/${file.replace(/index\.html$/, '')}`, // function to generate url from file path
contentTransformer: ({html, matches}) => html.replace('x', 'y'), // function to manipulate html string
backup: false, // default to backup when `contentTransformer` exists
raw: false, // return object[] in headers instead of string[]
})
/* output
[
{
source: '/zh/guide/',
headers: [
'</assets/js/3.f9aace0a.js>; rel=prefetch',
'</assets/js/24.b2ac9cbd.js>; rel=preload; as=script',
]
}
]
*/
Options
All options for globby plus :
raw
: boolean- default to
true
- customize type of returned
headers
property
- default to
urlTransformer
: function (singleFilePath)contentTransformer
: function ({html, matches}),backup
: string | boolean