Created
July 12, 2018 17:38
-
-
Save nsfmc/44ba92b5277e8e47fb75b09d0ec1b7a3 to your computer and use it in GitHub Desktop.
super minimal server react setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOMServer from 'react-dom/server'; | |
import express from 'express' | |
const app = express(); | |
app.get('/', (_, res) => { | |
console.log() | |
const App = () => <p>ohayo</p>; | |
const reactContent = ReactDOMServer.renderToString(<App />); | |
res.send(reactContent); | |
}); | |
const {PORT = 8181} = process.env; | |
console.log(`about to listen on 0.0.0.0:${PORT}`); | |
app.listen(PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "simple-server", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"scripts": { | |
"watch": "NODE_ENV=development webpack -w", | |
"build": "NODE_ENV=production webpack", | |
"serve": "nodemon dist/dist.js" | |
}, | |
"dependencies": { | |
"babel-core": "^6.26.3", | |
"babel-loader": "^7.1.5", | |
"babel-preset-env": "^1.7.0", | |
"babel-preset-react": "^6.24.1", | |
"express": "^4.16.3", | |
"nodemon": "^1.18.1", | |
"react": "^16.4.1", | |
"react-dom": "^16.4.1", | |
"webpack": "^4.16.0", | |
"webpack-cli": "^3.0.8" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
entry: './index.js', | |
output: { | |
filename: 'dist.js', | |
}, | |
devtool: 'source-map', | |
mode: process.env.NODE_ENV || 'production', | |
target: 'node', | |
module: { | |
rules: [ | |
{ | |
test: /\.jsx?$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: [['env', {'targets': {node: 'current'}}], 'react'], | |
} | |
} | |
}, | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment