Skip to content

Commit a866109

Browse files
F-X64major
authored andcommittedMay 23, 2023
Add HTML pre-rendering
Replace dr:surge with react-spa-prerender Add react-spa config Add new postbuild step
1 parent 4badb97 commit a866109

File tree

5 files changed

+5949
-5561
lines changed

5 files changed

+5949
-5561
lines changed
 

‎.rsp.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"port": 3000,
3+
"buildDirectory": "./dist",
4+
"engine": {
5+
"launchOptions": {
6+
"args": [
7+
"--no-sandbox",
8+
"--disable-setuid-sandbox"
9+
],
10+
"product": "chrome",
11+
"headless": true,
12+
"ignoreHTTPSErrors": true
13+
},
14+
"gotoOptions": {
15+
"timeout": 0
16+
}
17+
},
18+
"routes": [
19+
"/",
20+
"/browser/aws",
21+
"/browser/azure",
22+
"/browser/google",
23+
"/blog"
24+
]
25+
}

‎package-lock.json

+5,912-5,556
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"prop-types": "^15.8.1",
4545
"react-axe": "^3.5.4",
4646
"react-router-dom": "^6.6.2",
47+
"react-spa-prerender": "^1.0.14",
4748
"regenerator-runtime": "^0.13.11",
4849
"rimraf": "^5.0.0",
4950
"sass": "^1.60.0",
@@ -69,7 +70,7 @@
6970
"private": true,
7071
"repository": "https://github.com/redhatcloudx/cloud-image-directory-frontend",
7172
"scripts": {
72-
"build": "webpack --config webpack.prod.js && npm run dr:surge",
73+
"build": "webpack --config webpack.prod.js",
7374
"build:bundle-profile": "webpack --config webpack.prod.js --profile --json > stats.json",
7475
"bundle-profile:analyze": "npm run build:bundle-profile && webpack-bundle-analyzer ./stats.json",
7576
"ci-checks": "npm run type-check && npm run lint && npm run test:coverage",
@@ -79,6 +80,7 @@
7980
"format": "prettier --check --write ./src/**/*.{tsx,ts}",
8081
"lint": "npm run eslint",
8182
"prebuild": "npm run clean",
83+
"postbuild": "react-spa-prerender",
8284
"start": "sirv dist --cors --single --host --port 8080",
8385
"start:dev": "webpack serve --color --progress --stats-error-details --config webpack.dev.js",
8486
"test": "jest --watch",

‎src/index.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ if (process.env.NODE_ENV !== 'production') {
1515
const axe = require('react-axe')
1616
axe(React, ReactDOM, 1000, config)
1717
}
18+
const rootElement = document.getElementById("root") as HTMLElement;
1819

19-
ReactDOM.render(<App />, document.getElementById('root') as HTMLElement)
20+
if (rootElement.hasChildNodes()) {
21+
ReactDOM.hydrate(<App />, rootElement);
22+
} else {
23+
ReactDOM.render(<App />, rootElement);
24+
}

‎webpack.common.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const CopyPlugin = require('copy-webpack-plugin');
44
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
55
const Dotenv = require('dotenv-webpack');
66
const BG_IMAGES_DIRNAME = 'bgimages';
7-
const ASSET_PATH = process.env.ASSET_PATH || '/web-app/';
7+
const ASSET_PATH = process.env.ASSET_PATH || '/';
88
module.exports = env => {
99

1010
return {
@@ -99,12 +99,12 @@ module.exports = env => {
9999
},
100100
output: {
101101
filename: '[name].bundle.js',
102-
path: path.resolve(__dirname, 'dist/web-app'),
102+
path: path.resolve(__dirname, 'dist'),
103103
publicPath: ASSET_PATH
104104
},
105105
plugins: [
106106
new HtmlWebpackPlugin({
107-
filename: '../index.html',
107+
filename: 'index.html',
108108
template: path.resolve(__dirname, 'src', 'index.html')
109109
}),
110110
new Dotenv({

0 commit comments

Comments
 (0)
Please sign in to comment.