Actually, I am doing this to add SSR build folder(dist) to add inside of the build folder in React.js Redux.
Step 1: webpack.build.config.js
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build/dist'),
filename: 'bundle.js'
},
}
Step 2. webpack.server.config.js
const path = require('path');
const webpackNodeExternals = require('webpack-node-externals');
module.exports = {
mode: 'development',
target: 'node',
entry: './server/index.js',
output: {
path: path.resolve(__dirname),
filename: 'server.js'
},
}
Step 3. package.json
"scripts": {
"start": "react-scripts start && webpack-dev-server",
"cleanBuild": "rimraf ./build/*",
"build": "npm run cleanBuild && set \"GENERATE_SOURCEMAP=false\" && react-scripts build",
"server-build": "webpack --config webpack.build.config.js && webpack --config webpack.server.config.js",
"serve:ssr": "node server.js"
},
Step 4: Make Build
First, Build Normal
npm run build.
Second, build SSR
npm run server-build.
Third, run SSR Code & normal code by using node server.js and npm run start.