Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #8

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Next Next commit
ssr attempt
  • Loading branch information
alexrqs committed Dec 19, 2018
commit 3d7500a9bad96a55a03e4ff71f6c9b9bbb5c00d3
6 changes: 3 additions & 3 deletions examples/logo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dom from '../src/dom'
import dom from '../src/dom2'

const Logo = () => (
const Logo = ({ color } = {}) => (
<svg
id="Layer_1"
data-name="Layer 1"
@@ -13,7 +13,7 @@ const Logo = () => (
<path
d="M241.74,421.43v-41h28.61v41H241.74Zm24.47-4.13V384.56H245.86V417.3h20.35Z"
transform="translate(-241.74 -380.43)"
style={{ fill: '#ffcd05' }}
style={{ fill: `${color || '#ffcd05'}` }}
/>
<path
d="M289.36,398.82h-1.77c-2.32-3.28-4.63-6.54-6.93-10.23h0v10.23h-2V384.55h1.77c2.32,3.26,4.63,6.5,6.91,10.17h0V384.55h2v14.27Z"
25 changes: 25 additions & 0 deletions examples/ssr/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import dom from '../../src/dom2'
import Logo from '../logo'

const Headline = () => (
<div>
<h2 className="css">Title</h2>
<Logo color="#34ff90" />
<ul>
<li>
<a href="http://google.com">google</a>
</li>
<li>
<a href="http://google.com">google</a>
</li>
<li>
<a href="http://google.com">google</a>
</li>
<li>
<a href="http://google.com">google</a>
</li>
</ul>
</div>
)

export default Headline
7 changes: 7 additions & 0 deletions examples/ssr/front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dom from '../../src/dom2'

import renderFront from '../../src/dom.js'
import Component from './component'

// const { element, attrs, children } = renderFront(Component)
// console.log('renderFront(<Component />): ', renderFront(Component()));
29 changes: 29 additions & 0 deletions examples/ssr/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import express from 'express'
import Component from './component'
import render from '../../src/render'
import dom from '../../src/dom2'

const app = express()

app.use(express.static('examples/ssr/public'))

app.get('/', function root(req, res) {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>SSR</h1>
<div class="app">${render(<Component />)}</div>
<script src="/front.js"></script>
</body>
</html>
`)
})

app.listen(3030, function cb() {
console.log(3030)
})
29 changes: 29 additions & 0 deletions examples/ssr/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const path = require('path')
const HTMLPage = require('html-webpack-plugin')

module.exports = {
devtool: 'cheap-source-code',
entry: {
front: path.resolve(__dirname, './front.js'),
},

mode: 'development',

module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
extends: path.resolve(__dirname, '../../.babelrc'),
},
},
],
},

output: {
path: path.resolve('./examples/ssr/public/'),
filename: '[name].js',
},
}
27 changes: 13 additions & 14 deletions examples/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('path')
const HTMLPage = require('html-webpack-plugin')

module.exports = {
@@ -9,29 +9,28 @@ module.exports = {

devtool: 'cheap-source-code',
entry: {
main: path.resolve(__dirname, './index.js'),
front: path.resolve(__dirname, './front.js'),
},

mode: 'development',

module: {
rules: [{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
extends: path.resolve(__dirname, '../.babelrc'),
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
extends: path.resolve(__dirname, '../.babelrc'),
},
},
}]
],
},

output: {
path: path.resolve(''),
path: path.resolve('./examples/ssr/public/'),
filename: '[name].js',
},

plugins: [
new HTMLPage(),
],

plugins: [new HTMLPage()],
}
Loading