Skip to content

Repository files navigation

pages-webpack-plugin

Generate static pages with webpack.

build statuscoveragelicenseversiondownloads

Usage:

constPagesPlugin=require('pages-webpack-plugin');constrenderBody=(path)=>{switch(path){case'/':
return'See all our <a href="/products">Products</a>.';case'/products':
return'We have the hugest products.';default:
return'Page not found.';}}module.exports={// ...plugins: [newPagesPlugin({// Required ConfigmapStatsToProps: (stats)=>{// Map webpack stats object to render function propsreturn{stats: stats.toJson(/* webpack toJson options*/)};},render: (props)=>{const{stats, path}=props;constscriptSrc=stats.publicPath+stats.assetsByChunkName.main;constmarkup=` <!DOCTYPE html> <html> <body>${renderBody(path)} <script src="${scriptSrc}"></script> </body> </html> `constresult={markup,/* status, redirect */}returnresult;},// Optional Configpaths: ['/'],// Define initial seed routesmapResultToFilename(result){// Map rendered path to output file namereturnresult.path;},mapResults(results,compilation){// Intercept generated files before emitreturnresults.map((result)=>{returnresult;});},// Only explore the paths provided in the `paths` option// parsePathsFromMarkup: () => []}),],};

About

Generate arbitrary HTML pages through webpack.

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages