https://github.com/static-dev/spike-preact-ssr
Render preact components to static html through webpack
https://github.com/static-dev/spike-preact-ssr
Last synced: 9 months ago
JSON representation
Render preact components to static html through webpack
- Host: GitHub
- URL: https://github.com/static-dev/spike-preact-ssr
- Owner: static-dev
- License: other
- Created: 2017-04-27T15:53:59.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-27T16:09:55.000Z (almost 9 years ago)
- Last Synced: 2024-10-12T23:26:12.159Z (over 1 year ago)
- Language: JavaScript
- Size: 63.5 KB
- Stars: 6
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Spike Preact SSR
[](https://npmjs.com/package/spike-preact-ssr)
[](https://travis-ci.org/static-dev/spike-preact-ssr?branch=master)
[](https://david-dm.org/static-dev/spike-preact-ssr)
[](https://codecov.io/gh/static-dev/spike-preact-ssr)
Easily render [preact](https://github.com/developit/preact) components to HTML
> **Note:** This project is in early development, and versioning is a little different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.
### Installation
`yarn add spike-preact-ssr`
### Usage
Let's say you have some preact components in a folder under `assets/js/pages`, like this:
```js
export default ({ foo }) => {
return (
Hello there! Foo is {foo}
)
}
```
...and you want to prerender these as HTML. You'd just add the plugin to spike, and tell it where your component(s) are, and how to map them to an output path as such:
```js
const path = require('path')
const PreactSSR = require('spike-preact-ssr')
module.exports = {
// ...
plugins: [
new PreactSSR({
pages: 'assets/js/pages/*.js', // globstar syntax optional
props: { foo: 'bar' }, // props to pass to root component
output: (relativePath) => path.basename(relativePath).replace(/\.js$/, '.html') // by default it will map to its current location and just replace .js with .html
})
]
// ...
}
```
That's it! Run spike, and you'll see some nice pretty html rendered out as you wanted. If you have interactive components, you can then run them from JS as well and it will work just like normal server side rendering.
### License & Contributing
- Details on the license [can be found here](LICENSE.md)
- Details on running tests and contributing [can be found here](contributing.md)