Skip to content

Commit

Permalink
Add client bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
velvetkevorkian committed Mar 27, 2020
1 parent 38b2015 commit 1f328b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion rollup.config.js
Expand Up @@ -8,5 +8,14 @@ export default [
format: 'cjs',
},
plugins: [resolve()],
}
},
{
input: 'src/client.js',
output: {
file: 'build/client.js',
format: 'es',
name: 'client',
},
plugins: [resolve()],
},
]
4 changes: 4 additions & 0 deletions src/client.js
@@ -0,0 +1,4 @@
import { hydrate } from 'preact'
import PreactApp from './components/PreactApp'

hydrate(PreactApp(), document.getElementById('root'))
11 changes: 10 additions & 1 deletion src/server.js
Expand Up @@ -9,7 +9,9 @@ app.use(compression()) // use gzip for all requests

const body = render(html`
<h1>Hello from Preact</h1>
<${PreactApp} />
<div id="root">
<${PreactApp} />
</div>
`)

// some basic html to show
Expand All @@ -18,6 +20,7 @@ const layout =`
<html>
<body>
${body}
<script type="module" src="client.js" async></script>
</body>
</html>
`
Expand All @@ -26,4 +29,10 @@ app.get('/', (request, response) => { // listen for requests to the root path
response.send(layout) // send the HTML string
})

app.get('/client.js', (request, response) => {
response.sendFile('client.js', {
root: __dirname, // this will be the build folder
})
})

app.listen(3000) // listen for requests on port 3000

0 comments on commit 1f328b7

Please sign in to comment.