Metalsmith plugin to use React as a template engine
That's a really good question. This can be probably done with metalsmith, but this tool is not the right choice. Not front-end oriented enough.
Have a look to Next.js instead !
Note that this module doesn't handle jsx. You might use babel(-node) to handle that.
$ npm install metalsmith-react
import Metalsmith from "metalsmith"
import react from "metalsmith-react"
new Metalsmith("./")
.use(
react({
pattern: "**/*.md",
templatesPath: "modules", // default to "templates"
before: "<!doctype html>\n",
data: {
some: "data", // you might be able to consume that as props in the template
},
reactRender: "renderToStaticMarkup" //you can use "renderToString" if you want
})
)
.build(err => {if (err) {throw err}})
See tests for templates examples
Place to read react templates (class)
Name of the default template file (relative to templatesPath
)
Pattern to filter files. Used by multimatch
Object passed to React component in addition to the file itself.
Allows to prepend something before the rendered component (eg: {before: "<!doctype html>\n"}
)
Allows to append something after the rendered component
React render method. You can use "renderToString"
if you want.
- ⇄ Pull requests and ★ Stars are always welcome.
- For bugs and feature requests, please create an issue.
- Pull requests must be accompanied by passing automated tests (
$ npm test
).