mirror of
https://github.com/aleleba/create-react-ssr.git
synced 2025-01-09 21:46:56 -06:00
PR-753737: Se empieza a configurar el server side render y el servidor de express.
This commit is contained in:
parent
48b52105c6
commit
c4e836691b
6
package-lock.json
generated
Normal file
6
package-lock.json
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "create-react-ssr",
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {}
|
||||||
|
}
|
1
package.json
Normal file
1
package.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
@ -1,3 +1,7 @@
|
|||||||
|
#Environment
|
||||||
|
ENV= #Default production
|
||||||
|
#App Port
|
||||||
|
PORT= #Default 80
|
||||||
#Port of React App
|
#Port of React App
|
||||||
PORT_DEV= #Default Port 3000
|
#PORT_DEV= #Default Port 3000
|
||||||
PORT_RELOAD_DEV= #Default Port PORT_DEV
|
#PORT_RELOAD_DEV= #Default Port PORT_DEV
|
@ -1,8 +1,10 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
portDev: process.env.PORT_DEV ? process.env.PORT_DEV : 3000,
|
env: process.env.ENV ? process.env.ENV : 'production',
|
||||||
portReloadDev: process.env.PORT_RELOAD_DEV,
|
port: process.env.PORT ? process.env.PORT : 80,
|
||||||
|
// portDev: process.env.PORT_DEV ? process.env.PORT_DEV : 3000,
|
||||||
|
// portReloadDev: process.env.PORT_RELOAD_DEV,
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { config: config };
|
module.exports = { config: config };
|
@ -4,3 +4,7 @@ import App from './components/App';
|
|||||||
import './styles/global.sass';
|
import './styles/global.sass';
|
||||||
|
|
||||||
ReactDom.render(<App />, document.getElementById('app'));
|
ReactDom.render(<App />, document.getElementById('app'));
|
||||||
|
|
||||||
|
if (module.hot) {
|
||||||
|
module.hot.accept();
|
||||||
|
}
|
2692
src/package-lock.json
generated
2692
src/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack serve --config webpack.config.dev.js",
|
"start": "webpack serve --config webpack.config.dev.js",
|
||||||
|
"start:dev": "nodemon server/index",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"build": "webpack --config webpack.config.js"
|
"build": "webpack --config webpack.config.js"
|
||||||
},
|
},
|
||||||
@ -23,9 +24,12 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/aleleba/create-react-ssr#readme",
|
"homepage": "https://github.com/aleleba/create-react-ssr#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/register": "^7.17.7",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
|
"express": "^4.17.3",
|
||||||
"react": "^18.0.0",
|
"react": "^18.0.0",
|
||||||
"react-dom": "^18.0.0"
|
"react-dom": "^18.0.0",
|
||||||
|
"webpack": "^5.72.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.17.9",
|
"@babel/core": "^7.17.9",
|
||||||
@ -38,12 +42,14 @@
|
|||||||
"html-loader": "^3.1.0",
|
"html-loader": "^3.1.0",
|
||||||
"html-webpack-plugin": "^5.5.0",
|
"html-webpack-plugin": "^5.5.0",
|
||||||
"mini-css-extract-plugin": "^2.6.0",
|
"mini-css-extract-plugin": "^2.6.0",
|
||||||
|
"nodemon": "^2.0.15",
|
||||||
"sass": "^1.50.0",
|
"sass": "^1.50.0",
|
||||||
"sass-loader": "^12.6.0",
|
"sass-loader": "^12.6.0",
|
||||||
"style-loader": "^3.3.1",
|
"style-loader": "^3.3.1",
|
||||||
"terser-webpack-plugin": "^5.3.1",
|
"terser-webpack-plugin": "^5.3.1",
|
||||||
"webpack": "^5.72.0",
|
|
||||||
"webpack-cli": "^4.9.2",
|
"webpack-cli": "^4.9.2",
|
||||||
"webpack-dev-server": "^4.8.1"
|
"webpack-dev-middleware": "^5.3.1",
|
||||||
|
"webpack-dev-server": "^4.8.1",
|
||||||
|
"webpack-hot-middleware": "^2.25.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
src/server/index.js
Normal file
8
src/server/index.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
require('@babel/register')({
|
||||||
|
"presets": [
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react"
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
require('./server');
|
35
src/server/server.js
Normal file
35
src/server/server.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import { config } from '../config';
|
||||||
|
import webpack from 'webpack';
|
||||||
|
|
||||||
|
const { env, port } = config
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
if(env === 'development'){
|
||||||
|
console.log('Development Config')
|
||||||
|
const webpackConfig = require('../webpack.config.dev');
|
||||||
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
||||||
|
const webpackHotMiddleware = require('webpack-hot-middleware');
|
||||||
|
const compiler = webpack(webpackConfig);
|
||||||
|
const serverConfig = {
|
||||||
|
serverSideRender: true,
|
||||||
|
publicPath: webpackConfig.output.publicPath,
|
||||||
|
};
|
||||||
|
|
||||||
|
app
|
||||||
|
.use(webpackDevMiddleware(compiler, serverConfig))
|
||||||
|
.use(webpackHotMiddleware(compiler, {
|
||||||
|
path: "/reload_wss",
|
||||||
|
heartbeat: 1000,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('*', (req, res) => {
|
||||||
|
res.send({ hello: 'express'});
|
||||||
|
})
|
||||||
|
|
||||||
|
app.listen(port, (err) => {
|
||||||
|
if(err) console.error(err)
|
||||||
|
else console.log(`Server running on port ${port}`);
|
||||||
|
});
|
@ -1,11 +1,12 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
const { config: { portDev, portReloadDev } } = require('./config')
|
// const { config: { portDev, portReloadDev } } = require('./config');
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './frontend/index.js',
|
entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&overlay=false&reload=true', './frontend/index.js'],
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, 'build'),
|
path: path.resolve(__dirname, 'build'),
|
||||||
filename: 'bundle.js',
|
filename: 'bundle.js',
|
||||||
@ -40,6 +41,7 @@ module.exports = {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: './public/index.html',
|
template: './public/index.html',
|
||||||
filename: './index.html',
|
filename: './index.html',
|
||||||
@ -48,7 +50,7 @@ module.exports = {
|
|||||||
filename: '[name].css',
|
filename: '[name].css',
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
devServer: {
|
/* devServer: {
|
||||||
static: {
|
static: {
|
||||||
directory: path.join(__dirname, 'build')
|
directory: path.join(__dirname, 'build')
|
||||||
},
|
},
|
||||||
@ -62,5 +64,5 @@ module.exports = {
|
|||||||
port: portReloadDev ? portReloadDev : portDev,
|
port: portReloadDev ? portReloadDev : portDev,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
}, */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user