{"id":28169845,"url":"https://github.com/zavalit/statichtmlwebpackplugin","last_synced_at":"2025-05-15T16:18:51.898Z","repository":{"id":36512870,"uuid":"40818579","full_name":"zavalit/StaticHtmlWebpackPlugin","owner":"zavalit","description":"Webpack plugin to generate static html pages ","archived":false,"fork":false,"pushed_at":"2016-10-07T13:31:09.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T18:02:46.039Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zavalit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-16T13:18:00.000Z","updated_at":"2017-06-29T23:41:20.000Z","dependencies_parsed_at":"2022-09-16T22:51:16.548Z","dependency_job_id":null,"html_url":"https://github.com/zavalit/StaticHtmlWebpackPlugin","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zavalit%2FStaticHtmlWebpackPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zavalit%2FStaticHtmlWebpackPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zavalit%2FStaticHtmlWebpackPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zavalit%2FStaticHtmlWebpackPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zavalit","download_url":"https://codeload.github.com/zavalit/StaticHtmlWebpackPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374525,"owners_count":22060615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-15T16:18:51.698Z","updated_at":"2025-05-15T16:18:51.889Z","avatar_url":"https://github.com/zavalit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/zavalit/StaticHtmlWebpackPlugin.svg)](http://travis-ci.org/zavalit/StaticHtmlWebpackPlugin)\n# Static Html Webpack plugin\n\nIt's a webpack plugin that aims to make static html generation as simple and transparent as possible.\n\nYou may want to get use of it if your are care of:\n- SEO\n- Better performance\n- Decoupling Frontend from Backend by design\n\n#### Configuration\nIt's nothing more as just provide a plugin instance and ensure that your output's *libraryTarget*\nis equal to **umd** API. It should be enough to enable plugin to do his work.\n\n```\n// webpack.config.js\n\nvar StaticHtml = require(\"static-html-webpack-plugin\");\n\nmodule.exports = {\n  entry: {\n    server: __dirname + '/index.js'\n  },\n  output: {\n    path: __dirname + '/public',\n    filename: '[name].js',\n    libraryTarget: 'umd'\n  },\n  plugins: [new StaticHtml()]\n}\n\n```\nPlugin takes following options:\n\n```\n- htmlFilename: name of html file, that have to be generated (default is \"index.html\"),\n- prependDoctypeHtml: set \"\u003c!DOCTYPE html\u003e\" before your html (default is true),\n- appendHash: append hash to css and script files (default is true)\n\n```\nTo manipulate Plugin Options just provide it to Plugin instance like that:\n```\n plugins: [new StaticHtml({appendHash: false})]\n\n```\n\n\nYou may have noticed, that **entry** applies an object with a key/value pair ```server: __dirname + '/index.js'``` that is where all static generation relevant staff have to be handled. You are free to extend it with ```... client: __dirname + '/yourclient.js'``` in order to have a library that relies on client's objects like *window.document* that you don't have, when you generate your static html. **StaticHtmlWebpackPlugin** just doesn't care about anything that, is not relevant for server-side html generation, all it looks for is a **entry.server** key.\n\nTo provide your actual html you have to point to it:\n```\n// index.js\n\nmodule.exports = \"\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eStatic Html\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eHi, i'm so static\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n\"\n\n```\n\n#### Html based on React routes.\n\nYou can also generate a multiple pages at once by providing routes of react-router, for that case you have to provide an object in stead of plain html. The object have to look like this:\n\n```\n// index.js\n\nimport React from 'react';\nimport {renderToStaticMarkup} from 'react-dom/server';\nimport {RoutingContext, match} from 'react-router';\nimport routes from './routes.js';\n\n\nmodule.exports = {\n\n  'react-router' : {\n\n    getPaths: function(parser){\n      return parser(routes)\n    },\n\n    buildHtml: function(path, callback){\n       match({ routes, location: path }, (error, redirectLocation, renderProps) =\u003e {\n         callback(renderToStaticMarkup(\u003cRoutingContext {...renderProps} /\u003e))\n       })\n    }\n  }\n\n}\n\n```\nand for a sample routes like this:\n```\n// routes.js\nimport React from 'react'\nimport { Route, Link } from 'react-router'\n\nconst App = React.createClass({\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003ch1\u003eApp\u003c/h1\u003e\n        \u003cul\u003e\n          \u003cli\u003e\u003cLink to=\"/about\"\u003eAbout\u003c/Link\u003e\u003c/li\u003e\n        \u003c/ul\u003e\n        {this.props.children}\n      \u003c/div\u003e\n    )\n  }\n})\n\nconst About = React.createClass({\n  render() {\n    return \u003ch3\u003eAbout\u003c/h3\u003e\n  }\n})\n\n\nmodule.exports = (\n    \u003cRoute path=\"/\" component={App}\u003e\n      \u003cRoute path=\"about\" component={About} /\u003e\n    \u003c/Route\u003e\n)\n\n```\n\nIt'a also possible to define Routes as an Array, if you don't want to use JSX.\n\n```\nmodule.exports = [\n  { path: '/',\n    component: App,\n    childRoutes: [\n      { path: 'about', component: About }\n    ]\n  }\n]\n```\n\nyou will get 2 html files generated:\n```\npublic/index.html\npublic/about/index.html\n```\n\n\n#### Extend it.\n\nYou can use also write your own generators, just create another addon in ```node_modules/static-html-webapck-plugin/addons``` that has the following sceleton:\n\n```\n//youraddon.js\nmodule.exports = {\n  getPaths: function(routes){\n      let paths = [...];\n      ...\n      return paths;\n  }\n}\n```\n\nand reference to it in your entry file:\n```\n//index.js\nmodule.exports = {\n\n  'youraddon' : {\n\n    getPaths: function(parser){\n      return parser(routes)\n    },\n\n    buildHtml: function(path, callback){\n\n         // your logic to generate an html for a given path and provide it as an argument to a callback function\n\n    }\n  }\n\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzavalit%2Fstatichtmlwebpackplugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzavalit%2Fstatichtmlwebpackplugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzavalit%2Fstatichtmlwebpackplugin/lists"}