react-html-render
v1.0.3
Published
Generate html files from react components
Downloads
24
Maintainers
Readme
React html render
You can use this to generate a html
file with react
component or output a html
using react server side rendering
.
Install
npm install react-html-render
Write config
- default:
render.config.js
- example:
var path = require('path');
module.exports = {
entry: {
"index": {
path: path.join(__filename, './../base.pug'),
options: {
"context": {path: path.join(__filename, "./../../lib/component"), props: {id: "1"}}
}
}
},
output: {
filename: "[name].html",
path: path.join(__filename, "./../")
}
};
- Every object in
entry
will generate ahtml
file. - Every object in
entry
:- path -> the path of
pug
file (If you do not know what ispug
, you can see here). If you do not set a path, this object will just combine every object inoptions
. - options -> the options of
pug
file. If you want to use react component, you need to write an object which havepath
, the path of react component. If you need to useprops
, you just need to addprops
in object.
- path -> the path of
output
:- filename -> filename is the name for output file and
[name]
will be replaced with the key of every object inentry
.defulat: [name].html
- path -> the path for output files.
default: the same path as render.config.js
- filename -> filename is the name for output file and
Usage in command
./node_modules/.bin/renderHTML
- Use other config:
./node_modules/.bin/renderHTML --config render.config.js
Usage in file
var path = require('path');
var process = require('process');
var render = require('react-html-render');
var output = render(path.join(process.cwd(), '..', './render.config.js'));
console.log(output);
- You just need to give a path of
react.config.js
toreact-html-render
function.