react-html-stringifier
v0.7.0
Published
Easy way to yield a plain-html web page without any JS from your React website
Downloads
15
Maintainers
Readme
React Stringifier
This package is designed for:
- extremely lightweight single page static websites ("landing pages")
- based on create-react-app (without eject)
It produces a html-file without a React js-bundle.
3 simple steps
- Install the package:
npm i -D react-html-stringifier
oryarn add -D react-html-stringifier
- Add this line to a
scripts
section of thepackage.json
:"static": "react-scripts build && react-html-stringifier"
- Run:
npm run static
oryarn static
Explanation
- Stringifier will copy the content of your
build
directory to a new one calledstatic
to work with it. - Then it injects a content of
browser-script.js
into yourindex.html
file and starts anexpress
server. - It serves a website and receives its HTML via POST request from
browser-script.js
. - (optional) Then HTML is received the server removes a React bundle and a
browser-script.js
script from it.
Settings
In the package.json
create a property stringifier
. These are defaults:
"stringifier": {
"input": "build",
"output": "docs",
"host": "localhost",
"port": 8765,
"timeout": 300,
"removeBundle": false
}
timeout
is needed to ensure React is rendered. It's the time after the page loaded and before its HTML is sent to the Stringifier.
Known Problems (may be fixed later)
- It does not work on Windows (uses shell commands for copying directories).