Skip to content

Commit d2e84ba

Browse files
committed
Initial commit
0 parents  commit d2e84ba

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-0
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"loose": "all",
3+
"modules": "umd",
4+
"sourceMaps": true,
5+
"nonStandard": true,
6+
"compact": true,
7+
"comments": false,
8+
"jsxPragma": "h"
9+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"parser": "babel-eslint",
3+
"ignore": ["*.md"]
4+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dist
2+
/node_modules
3+
/npm-debug.log
4+
.DS_Store

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.eslintrc

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# preact-render-to-string [![NPM](http://img.shields.io/npm/v/preact-render-to-string.svg)](https://www.npmjs.com/package/preact-render-to-string)
2+
3+
Render JSX and [Preact] components to an HTML string.
4+
5+
Works in Node & the browser, making it useful for universal/isomorphic rendering.
6+
7+
8+
### Render JSX/VDOM to HTML
9+
10+
```js
11+
import render from 'preact-render-to-string';
12+
import { h } from 'preact';
13+
/** @jsx h */
14+
15+
let vdom = <div class="foo">content</div>;
16+
17+
let html = render(vdom);
18+
console.log(html);
19+
// <div class="foo">content</div>
20+
```
21+
22+
23+
### Render Preact Components to HTML
24+
25+
```js
26+
import render from 'preact-render-to-string';
27+
import { h, Component } from 'preact';
28+
/** @jsx h */
29+
30+
// Classical components work
31+
class Fox extends Component {
32+
render({ name }) {
33+
return <span class="fox">{ name }</span>;
34+
}
35+
}
36+
37+
// ... and so do pure functional components:
38+
const Box = ({ type, children }) => (
39+
<div class={`box box-${type}`}>{ children }</div>
40+
);
41+
42+
let html = render(
43+
<Box type="open">
44+
<Fox name="Finn" />
45+
</Box>
46+
);
47+
48+
console.log(html);
49+
// <div class="box box-open"><span class="fox">Finn</span></div>
50+
```
51+
52+
[Preact]: https://github.com/developit/preact

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "preact-render-to-string",
3+
"version": "1.0.0",
4+
"description": "Render JSX to an HTML string, with support for Preact components.",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "babel src -s -d dist",
8+
"test": "eslint {src,test} && mocha --compilers js:babel/register test/**/*.js",
9+
"prepublish": "npm run build",
10+
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
11+
},
12+
"keywords": [
13+
"preact",
14+
"photon",
15+
"electron"
16+
],
17+
"author": "Jason Miller <[email protected]>",
18+
"license": "ISC",
19+
"devDependencies": {
20+
"babel": "^5.8.23",
21+
"babel-eslint": "^4.1.3",
22+
"chai": "^3.3.0",
23+
"eslint": "^1.7.1",
24+
"mocha": "^2.3.3",
25+
"sinon": "^1.17.1",
26+
"sinon-chai": "^2.8.0"
27+
}
28+
}

0 commit comments

Comments
 (0)