{"id":15890200,"url":"https://github.com/hph/stateful-react-container-webpack-plugin","last_synced_at":"2025-07-20T22:06:33.512Z","repository":{"id":57369968,"uuid":"61383074","full_name":"hph/stateful-react-container-webpack-plugin","owner":"hph","description":"A simple plugin that adds a React container element with initial state from the server to a template built with html-webpack-plugin.","archived":false,"fork":false,"pushed_at":"2019-04-18T12:48:30.000Z","size":9,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-06T23:38:15.352Z","etag":null,"topics":["html-webpack-plugin","react","webpack"],"latest_commit_sha":null,"homepage":"","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/hph.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":"2016-06-17T15:18:41.000Z","updated_at":"2023-03-10T10:08:26.000Z","dependencies_parsed_at":"2022-09-09T13:22:13.529Z","dependency_job_id":null,"html_url":"https://github.com/hph/stateful-react-container-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hph/stateful-react-container-webpack-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hph%2Fstateful-react-container-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hph%2Fstateful-react-container-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hph%2Fstateful-react-container-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hph%2Fstateful-react-container-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hph","download_url":"https://codeload.github.com/hph/stateful-react-container-webpack-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hph%2Fstateful-react-container-webpack-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266205420,"owners_count":23892463,"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":["html-webpack-plugin","react","webpack"],"created_at":"2024-10-06T07:04:30.657Z","updated_at":"2025-07-20T22:06:33.497Z","avatar_url":"https://github.com/hph.png","language":"JavaScript","readme":"# stateful-react-container-webpack-plugin\n\nThis [Webpack](https://webpack.github.io/) plugin in intended to be used with\n[html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) in\nprojects using React.js. This plugin allows you to use html-webpack-plugin to\nbuild templates automatically with Webpack while also server-side rendering and\npassing initial state to the React.js client-side app.\n\nThere may be an example of the usage over at [Kit](https://github.com/hph/kit)\nwhen I've had time to update it. See the [Example output](#Example-output) to\nget an idea what this does.\n\n### Installation\n\n    npm install -S stateful-react-container-webpack-plugin\n\n### Setup\n\nAfter installing the plugin, you will need to add it to the plugins in your\nWebpack configuration:\n\n```javascript\nplugins: [\n  new HtmlWebpackPlugin(),\n  new StatefulReactContainerPlugin(),\n],\n```\n\n### Options\n\nThe plugin provides three options (passed as an object argument to the plugin)\nto customize usage:\n\n- `id` (default: `container`): The id of the React container.js element.\n- `attribute` (default: `state`): The name of the data attribute to store the\n  initial state for the React.js app.\n- `variable` (default: `state`): The name of the variable containing the\n  initial state in the template.\n- `noState` (default: `false`): Omits the data attribute and its value. This is\n  useful if you only want this plugin to generate the container element and are\n  not using server rendering.\n- `position` (default: `'start'`): Determines whether the container is\n  immediately after the opening body tag or immediately before the closing tag.\n  Can be either `'start'` or `'end'`.\n\n### Example output\n\nWith the default configuration, the `\u003cbody\u003e` tag is replaced with the following\nmarkup:\n\n```html\n\u003cbody\u003e\u003cdiv id=\"container\" data-state=\"\u003c%= state %\u003e\"\u003e\u003c/div\u003e\n```\n\n### Notes\n\nThis plugin assumes that you're using `ejs` to render your templates on the\nserver side (hence the `\u003c%= state %\u003e` in the output). Using Express.js, you\nmight render the built template as follows:\n\n```javascript\n// in a request handler\nconst state = JSON.stringify({\n  user: req.session.user,\n});\nres.render('app.ejs', { state });\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhph%2Fstateful-react-container-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhph%2Fstateful-react-container-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhph%2Fstateful-react-container-webpack-plugin/lists"}