PR-536602: updating packages and fixing vendors.css error.

This commit is contained in:
Alejandro Lembke Barrientos 2022-08-10 21:42:46 +00:00
parent 73056ae8bd
commit 5780bae041
8 changed files with 41 additions and 31 deletions

18
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@aleleba/create-react-ssr", "name": "@aleleba/create-react-ssr",
"version": "3.0.51", "version": "3.1.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@aleleba/create-react-ssr", "name": "@aleleba/create-react-ssr",
"version": "3.0.51", "version": "3.1.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@babel/register": "^7.18.9", "@babel/register": "^7.18.9",
@ -49,7 +49,7 @@
"@testing-library/react": "^13.3.0", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^14.4.3", "@testing-library/user-event": "^14.4.3",
"@types/jest": "^28.1.6", "@types/jest": "^28.1.6",
"@types/node": "^18.6.5", "@types/node": "^18.7.0",
"@types/react": "^18.0.17", "@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/webpack": "^5.28.0", "@types/webpack": "^5.28.0",
@ -3516,9 +3516,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.6.5", "version": "18.7.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.5.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.0.tgz",
"integrity": "sha512-Xjt5ZGUa5WusGZJ4WJPbOT8QOqp6nDynVFRKcUt32bOgvXEoc6o085WNkYTMO7ifAj2isEfQQ2cseE+wT6jsRw==" "integrity": "sha512-MbHwEQaMKgcSQE3vFHUvxiN0+k3VpwCbnYCUigQWoKZzdIk2u7ecoCk5Vzb4lwBbKhLd2rCOUUDT35TaONs7Jw=="
}, },
"node_modules/@types/parse5": { "node_modules/@types/parse5": {
"version": "6.0.3", "version": "6.0.3",
@ -18081,9 +18081,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "18.6.5", "version": "18.7.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.5.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.0.tgz",
"integrity": "sha512-Xjt5ZGUa5WusGZJ4WJPbOT8QOqp6nDynVFRKcUt32bOgvXEoc6o085WNkYTMO7ifAj2isEfQQ2cseE+wT6jsRw==" "integrity": "sha512-MbHwEQaMKgcSQE3vFHUvxiN0+k3VpwCbnYCUigQWoKZzdIk2u7ecoCk5Vzb4lwBbKhLd2rCOUUDT35TaONs7Jw=="
}, },
"@types/parse5": { "@types/parse5": {
"version": "6.0.3", "version": "6.0.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@aleleba/create-react-ssr", "name": "@aleleba/create-react-ssr",
"version": "3.1.0", "version": "3.1.1",
"description": "Starter Kit of server side render of react", "description": "Starter Kit of server side render of react",
"bin": "./bin/cli.js", "bin": "./bin/cli.js",
"main": "src/server/index", "main": "src/server/index",
@ -68,7 +68,7 @@
"@testing-library/react": "^13.3.0", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^14.4.3", "@testing-library/user-event": "^14.4.3",
"@types/jest": "^28.1.6", "@types/jest": "^28.1.6",
"@types/node": "^18.6.5", "@types/node": "^18.7.0",
"@types/react": "^18.0.17", "@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/webpack": "^5.28.0", "@types/webpack": "^5.28.0",

View File

@ -8,7 +8,7 @@ const OtherComponent = () => (
<header className="App-header"> <header className="App-header">
<img src={logo} className="App-logo" alt="logo" /> <img src={logo} className="App-logo" alt="logo" />
<p> <p>
Edit src/frontend/OtherComponent.jsx and save to reload. Edit <code>src/frontend/OtherComponent.jsx</code> and save to reload.
</p> </p>
<Link className="App-link" to="/">Initial Component</Link> <Link className="App-link" to="/">Initial Component</Link>
</header> </header>

View File

@ -1,13 +0,0 @@
import fs from 'fs';
const getHashManifest = () => {
try {
const baseUrl = __dirname.replace(/\/server(.*)/,'');
const fullURL = `${baseUrl}/assets/manifest-hash.json` ;
return JSON.parse(fs.readFileSync(fullURL).toString());
}catch(err){
console.error(err);
}
};
export default getHashManifest;

View File

@ -20,7 +20,7 @@ import { Provider } from 'react-redux';
import setStore from '../frontend/setStore'; import setStore from '../frontend/setStore';
import initialState from '../frontend/reducers/initialState'; import initialState from '../frontend/reducers/initialState';
//Get Hashes //Get Hashes
import getHashManifest from './getHashManifest'; import { getHashManifest, haveVendorsCss } from './utilsServer';
//App //App
import App from '../frontend/components/App'; import App from '../frontend/components/App';
@ -67,8 +67,8 @@ if(env === 'development'){
} }
const setResponse = (html, preloadedState, manifest) => { const setResponse = (html, preloadedState, manifest) => {
const mainStyles = manifest ? manifest['frontend.css'] : 'assets/main/app.css'; const mainStyles = manifest ? manifest['frontend.css'] : 'assets/main.css';
const vendorStyles = manifest ? manifest['vendors.css'] : '/assets/vendors/app.css'; const vendorStyles = manifest ? manifest['vendors.css'] : 'assets/vendors.css';
const mainBuild = manifest ? manifest['frontend.js'] : 'assets/app.js'; const mainBuild = manifest ? manifest['frontend.js'] : 'assets/app.js';
const vendorBuild = manifest ? manifest['vendors.js'] : 'assets/vendor.js'; const vendorBuild = manifest ? manifest['vendors.js'] : 'assets/vendor.js';
const manifestJson = manifest ? `<link rel="manifest" href="${manifest['manifest.json']}">` : ''; const manifestJson = manifest ? `<link rel="manifest" href="${manifest['manifest.json']}">` : '';
@ -84,7 +84,7 @@ const setResponse = (html, preloadedState, manifest) => {
<meta name="theme-color" content="#000000"> <meta name="theme-color" content="#000000">
${manifestJson} ${manifestJson}
<link href="${mainStyles}" rel="stylesheet" type="text/css"></link> <link href="${mainStyles}" rel="stylesheet" type="text/css"></link>
<link href="${vendorStyles}" rel="stylesheet" type="text/css"></link> ${haveVendorsCss() ? `<link href="${vendorStyles}" rel="stylesheet" type="text/css"></link>` : ''}
<title>App</title> <title>App</title>
</head> </head>
<body> <body>

23
src/server/utilsServer.ts Normal file
View File

@ -0,0 +1,23 @@
import fs from 'fs';
export const getHashManifest = () => {
try {
const baseUrl = __dirname.replace(/\/server(.*)/,'');
const fullURL = `${baseUrl}/assets/manifest-hash.json` ;
return JSON.parse(fs.readFileSync(fullURL).toString());
}catch(err){
console.error(err);
}
};
export const haveVendorsCss = () => {
try {
const baseUrl = __dirname.replace(/\/server(.*)/,'');
const fullURL = `${baseUrl}/assets/vendors.css` ;
fs.readFileSync(fullURL).toString();
return true
}catch(err){
// console.error(err);
return false
}
};

View File

@ -69,7 +69,7 @@ const config: Configuration = {
new webpack.HotModuleReplacementPlugin(), new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(), new ReactRefreshWebpackPlugin(),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'assets/[name]/app.css', filename: 'assets/[name].css',
}), }),
new ESLintPlugin(), new ESLintPlugin(),
new webpack.DefinePlugin({ new webpack.DefinePlugin({

View File

@ -76,7 +76,7 @@ const frontendConfig = {
filename: '[path][base].gz', filename: '[path][base].gz',
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'assets/[name]/app-[fullhash].css', filename: 'assets/[name]-[fullhash].css',
}), }),
new WebpackManifestPlugin({ new WebpackManifestPlugin({
fileName: 'assets/manifest-hash.json', fileName: 'assets/manifest-hash.json',