1.0.3 • Published 9 years ago
react-html-render v1.0.3
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-renderWrite 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
entrywill generate ahtmlfile. - Every object in
entry:- path -> the path of
pugfile (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
pugfile. 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 addpropsin 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.jsUsage 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.jstoreact-html-renderfunction.